From a67ca9db199a6fe4ba689c6b12b11b35cb44948f Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 28 Nov 2020 13:23:58 -0500 Subject: [PATCH] Convert lua files to unix line endings --- unpacked.ttslua | 1484 ++++---- unpacked/Custom_Model 032300.ttslua | 224 +- unpacked/Custom_Model 1769ed.ttslua | 224 +- unpacked/Custom_Model 37be78.ttslua | 224 +- unpacked/Custom_Model d86b7c.ttslua | 224 +- ...tom_Model Custom Data Helper c0b834.ttslua | 70 +- ...ustom_Model_Bag Arkhamdb bag b85d6d.ttslua | 70 +- .../Custom_Model_Bag Chaos Bag fea079.ttslua | 8 +- ...del_Bag Clue Counter Swapper d919d6.ttslua | 544 +-- .../Custom_Token Doom counter 19768a.ttslua | 262 +- .../Custom_Token Resources 3f22e5.ttslua | 260 +- .../Custom_Token Resources 4111de.ttslua | 260 +- .../Custom_Token Resources 891403.ttslua | 260 +- .../Custom_Token Resources db85d6.ttslua | 260 +- ...ergence Custom Investigators 84be1d.ttslua | 1004 ++--- ...Gender Swapped Investigators 33272e.ttslua | 1004 ++--- ...houghts Custom Investigators 991ff9.ttslua | 1004 ++--- ...vestigators and Player Cards 54bd65.ttslua | 1004 ++--- ...stom_Model_Bag Investigators fba392.ttslua | 1006 ++--- ...ustom_Model_Bag Player Cards 64ad17.ttslua | 1006 ++--- ...Edition Custom Investigators 1fb7ce.ttslua | 1004 ++--- ...e Aeons Custom Investigators 991ff9.ttslua | 1004 ++--- unpacked/Custom_Model_Bag Core 2585f4.ttslua | 1004 ++--- unpacked/Custom_Model_Bag Core 64a613.ttslua | 1004 ++--- ...om_Model_Bag 1 The Gathering 667111.ttslua | 546 +-- .../Custom_Tile Core Difficulty 92d5f1.ttslua | 40 +- ...del_Bag 2 The Midnight Masks c38c96.ttslua | 546 +-- .../Custom_Tile Core Set 8112ff.ttslua | 40 +- ...del_Bag 3 The Devourer Below 2130f0.ttslua | 546 +-- ...stom_Tile The Devourer Below 37feeb.ttslua | 40 +- ...t of the Zealot Campaign Log e0c3e7.ttslua | 1356 +++---- ...oken Scenario - EasyStandard b7af99.ttslua | 262 +- ...oken Scenario - EasyStandard e19c97.ttslua | 262 +- ...oken Scenario - EasyStandard 535979.ttslua | 262 +- ..._Token Scenario - HardExpert 9ed124.ttslua | 262 +- .../Custom_Token Scenario 2da146.ttslua | 262 +- .../Custom_Token Scenario dd61f1.ttslua | 262 +- .../Custom_Model_Bag Guardian 1d802b.ttslua | 1004 ++--- .../Custom_Model_Bag Guardian bc3210.ttslua | 1004 ++--- .../Custom_Model_Bag Guardian cd002a.ttslua | 1004 ++--- .../Custom_Model_Bag Guardian a3401d.ttslua | 1004 ++--- ... Pegasus Custom Investigator 84be1d.ttslua | 1004 ++--- ...m_Model_Bag Miskatonic Mouse 0954ef.ttslua | 1006 ++--- ...tom_Model Custom Data Helper aa3d8a.ttslua | 76 +- .../Custom_Model_Bag Mystic 6117a1.ttslua | 1004 ++--- .../Custom_Model_Bag Mystic 2c2b99.ttslua | 1004 ++--- .../Custom_Model_Bag Mystic b4d9bf.ttslua | 1004 ++--- .../Custom_Model_Bag Mystic ee21f7.ttslua | 1004 ++--- .../Custom_Model_Bag Neutral a4d0e8.ttslua | 1004 ++--- .../Custom_Model_Bag Neutral 06b03b.ttslua | 1004 ++--- .../Custom_Model_Bag Neutral aef7dd.ttslua | 1004 ++--- .../Custom_Model_Bag Neutral 574514.ttslua | 1004 ++--- .../Custom_Model_Bag Neutral c5261f.ttslua | 1004 ++--- .../Custom_Model_Bag Neutral 3fe354.ttslua | 1004 ++--- ...odel_Bag Promo Investigators 5fe24e.ttslua | 1004 ++--- ...Return to The Dunwich Legacy ce9130.ttslua | 1006 ++--- ... 1a Extracurricular Activity d33f7e.ttslua | 1006 ++--- ...stom_Tile The Dunwich Legacy a74352.ttslua | 42 +- ...Bag 1b The House Always Wins f52082.ttslua | 1006 ++--- ...stom_Tile The Dunwich Legacy 1d6227.ttslua | 42 +- ..._Bag 2 The Miskatonic Museum 87897a.ttslua | 1006 ++--- ...m_Tile The Miskatonic Museum 4b5e17.ttslua | 50 +- ...g 3 The Essex County Express d92b86.ttslua | 1006 ++--- ...ile The Essex County Express 247967.ttslua | 50 +- ...del_Bag 4 Blood on the Altar 1536e7.ttslua | 1006 ++--- ...stom_Tile Blood on the Altar 92b54a.ttslua | 50 +- ...g 5 Undimensioned and Unseen a82dde.ttslua | 1006 ++--- ...ile Undimensioned and Unseen 393c71.ttslua | 50 +- ...odel_Bag 6 Where Doom Awaits 175a29.ttslua | 1006 ++--- ...ustom_Tile Where Doom Awaits a621ae.ttslua | 50 +- ...Bag 7 Lost in Time and Space 1fca6b.ttslua | 1006 ++--- ..._Tile Lost in Time and Space 64a607.ttslua | 50 +- ... Dunwich Legacy Campaign Log 3f6ab6.ttslua | 1338 +++---- ... Return to The Forgotten Age 479ff3.ttslua | 1006 ++--- ... Return to The Untamed Wilds 85a0c2.ttslua | 1004 ++--- ...ustom_Tile The Forgotten Age e95200.ttslua | 40 +- ... Return to The Doom of Eztli 110ce2.ttslua | 1004 ++--- ...ustom_Tile The Doom of Eztli 294ec4.ttslua | 48 +- ... 3 Return to Threads of Fate 499940.ttslua | 1004 ++--- .../Custom_Tile Threads of Fate 7a95f6.ttslua | 48 +- ...eturn to The Boundary Beyond 952af4.ttslua | 1004 ++--- ...tom_Tile The Boundary Beyond 010761.ttslua | 48 +- ...o Heart of the Elders Part 1 5abc8f.ttslua | 1004 ++--- ...tom_Tile Heart of the Elders 493cb1.ttslua | 48 +- ...o Heart of the Elders Part 2 3ccabf.ttslua | 1004 ++--- ...turn to The City of Archives e73427.ttslua | 1004 ++--- ...om_Tile The City of Archives 2fb6dc.ttslua | 48 +- ...Return to The Depths of Yoth 9c986e.ttslua | 1004 ++--- ...stom_Tile The Depths of Yoth 7aa4e3.ttslua | 48 +- ...oken Scenario - EasyStandard dd61f1.ttslua | 262 +- ..._Token Scenario - HardExpert 2da146.ttslua | 262 +- ... 8 Return to Shattered Aeons 5e83e7.ttslua | 1004 ++--- .../Custom_Tile Shattered Aeons 6dc72a.ttslua | 42 +- ... 9 Return to Secret Scenario 496395.ttslua | 1004 ++--- ...e Forgotten Age Campaign Log 48b154.ttslua | 1380 +++---- ...eturn to The Path to Carcosa e9889a.ttslua | 1006 ++--- ...tom_Model_Bag 1 Curtain Call 83ccd4.ttslua | 546 +-- ...tom_Tile The Path to Carcosa 16562e.ttslua | 42 +- ...om_Model_Bag 2 The Last King 6730a1.ttslua | 546 +-- .../Custom_Tile The Last King 857d0d.ttslua | 48 +- ...del_Bag 3 Echoes of the Past 42d2dc.ttslua | 546 +-- ...stom_Tile Echoes of the Past 452210.ttslua | 50 +- ...l_Bag 4 The Unspeakable Oath e7efa6.ttslua | 546 +-- ...om_Tile The Unspeakable Oath 87f45e.ttslua | 50 +- ...del_Bag 5 A Phantom of Truth bd4167.ttslua | 546 +-- ...stom_Tile A Phantom of Truth b20b8d.ttslua | 50 +- ..._Model_Bag 6 The Pallid Mask eb48ff.ttslua | 546 +-- .../Custom_Tile The Pallid Mask bb070d.ttslua | 50 +- ...Model_Bag 7 Black Stars Rise dd8b0d.ttslua | 546 +-- .../Bag Setup Bag b29b71.ttslua | 546 +-- .../Bag Setup Bag d14543.ttslua | 546 +-- ...Custom_Tile Black Stars Rise 20c21d.ttslua | 50 +- ...stom_Model_Bag 8 Dim Carcosa ce5d30.ttslua | 546 +-- .../Custom_Tile Dim Carcosa 9afdfd.ttslua | 50 +- ...om_Tile Carcosa Campaign Log ae8317.ttslua | 1510 ++++---- ...n to the Night of the Zealot 56270d.ttslua | 1006 ++--- ...ag 1 Return to The Gathering 41ebd8.ttslua | 546 +-- .../Custom_Tile Core Difficulty 527f29.ttslua | 40 +- ...Return to The Midnight Masks bcc86c.ttslua | 546 +-- .../Custom_Tile Core Difficulty 47f3de.ttslua | 40 +- ...Return to The Devourer Below 604753.ttslua | 546 +-- ...t of the Zealot Campaign Log e0c3e7.ttslua | 1356 +++---- unpacked/Custom_Model_Bag Rogue 68d7b8.ttslua | 1004 ++--- .../Custom_Model_Bag Rogue 21d547.ttslua | 1004 ++--- unpacked/Custom_Model_Bag Rogue deaa6d.ttslua | 1004 ++--- .../Custom_Model_Bag Rogue fa4d49.ttslua | 1004 ++--- .../Custom_Model_Bag Seeker 1e7fc5.ttslua | 1004 ++--- .../Custom_Model_Bag Seeker e328ea.ttslua | 1004 ++--- .../Custom_Model_Bag Seeker 5ec2fb.ttslua | 1004 ++--- .../Custom_Model_Bag Seeker d99b16.ttslua | 1004 ++--- ...g Starter Deck Investigators 35fb9c.ttslua | 1004 ++--- .../Custom_Model_Bag Survivor 9c814b.ttslua | 1004 ++--- .../Custom_Model_Bag Survivor 3c40d9.ttslua | 1004 ++--- .../Custom_Model_Bag Survivor c02830.ttslua | 1004 ++--- .../Custom_Model_Bag Survivor f15fc1.ttslua | 1004 ++--- ..._Model_Bag The Circle Undone 0dcbe8.ttslua | 1004 ++--- ..._Model_Bag The Circle Undone 63e097.ttslua | 1004 ++--- ...odel_Bag 1 The Witching Hour 67a775.ttslua | 544 +-- ...ustom_Tile The Circle Undone f697b0.ttslua | 42 +- ...el_Bag 2 At Death's Doorstep 7388bc.ttslua | 546 +-- ...tom_Tile At Death's Doorstep b21125.ttslua | 46 +- ..._Model_Bag 3 The Secret Name 5c79d0.ttslua | 544 +-- .../Custom_Tile The Secret Name b21125.ttslua | 46 +- ...Model_Bag 4 The Wages of Sin 1e45e8.ttslua | 544 +-- ...Custom_Tile The Wages of Sin b21125.ttslua | 46 +- ...l_Bag 5 For the Greater Good a61b48.ttslua | 544 +-- .../Bag Member of the Lodge 38a5f7.ttslua | 546 +-- ...ag Not a Member of the Lodge abe15f.ttslua | 546 +-- ...om_Tile For the Greater Good bbb70a.ttslua | 48 +- ..._Bag 6 Union and Disillusion 20f70a.ttslua | 544 +-- ...m_Tile Union and Disillusion 3fe126.ttslua | 48 +- ...g 7 In the Clutches of Chaos 1ee775.ttslua | 546 +-- ...te Mason is posessed by evil d14543.ttslua | 546 +-- ... the secrets of the universe 92c6fc.ttslua | 546 +-- ...ile In the Clutches of Chaos e0709b.ttslua | 48 +- ...ag 8 Before the Black Throne 0fad66.ttslua | 546 +-- ...Tile Before the Black Throne b16392.ttslua | 48 +- ...rance at the Twilight Estate 2f008a.ttslua | 546 +-- ...ustom_Tile The Circle Undone 05f912.ttslua | 42 +- ...Circle Undone Campaign Log 1 44a05a.ttslua | 1304 +++---- ...m_Model_Bag The Dream-Eaters a16a1a.ttslua | 1004 ++--- ...-A Beyond the Gates of Sleep 7f5828.ttslua | 546 +-- ...Custom_Tile Campaign A Setup 075016.ttslua | 50 +- ...del_Bag 1-B Waking Nightmare 599cb7.ttslua | 544 +-- ...om_Model_Bag Infestation Bag 0257a2.ttslua | 8 +- ...Custom_Tile Campaign B Setup bbb70a.ttslua | 50 +- ...ag 2-A The Search For Kadath 7b07ca.ttslua | 544 +-- ...m_Tile The Search For Kadath bbb70a.ttslua | 50 +- ... A Thousand Shapes of Horror 1b4f86.ttslua | 544 +-- ... A Thousand Shapes of Horror b53295.ttslua | 50 +- ...ag 3-A Dark Side of the Moon 0fad66.ttslua | 544 +-- ...m_Tile Dark Side of the Moon aa8d82.ttslua | 50 +- ...l_Bag 3-B Point of No Return 4f81cf.ttslua | 544 +-- ...stom_Tile Point of No Return f302ab.ttslua | 50 +- ...Bag 4-A Where the Gods Dwell 185096.ttslua | 544 +-- ...stom_Tile Point of No Return 3e86c2.ttslua | 50 +- ...Bag 4-B Weaver of the Cosmos e14c76.ttslua | 546 +-- .../Bag Atlach-Nacha d14543.ttslua | 546 +-- ...om_Tile Weaver of the Cosmos bbb70a.ttslua | 48 +- ...The Dream-Quest Campaign Log f40183.ttslua | 1442 +++---- ...m_Model_Bag The Dream-Eaters a34f34.ttslua | 1004 ++--- ...Model_Bag The Dunwich Legacy 2898f6.ttslua | 1004 ++--- ... 1a Extracurricular Activity 51c0d9.ttslua | 1006 ++--- ...stom_Tile The Dunwich Legacy f5db25.ttslua | 42 +- ...Bag 1b The House Always Wins e3aa5c.ttslua | 1006 ++--- ...stom_Tile The Dunwich Legacy b5928a.ttslua | 42 +- ..._Bag 2 The Miskatonic Museum 87adbf.ttslua | 1006 ++--- ...m_Tile The Miskatonic Museum 703373.ttslua | 50 +- ...g 3 The Essex County Express d6e449.ttslua | 1006 ++--- ...ile The Essex County Express 247967.ttslua | 50 +- ...del_Bag 4 Blood on the Altar 30684d.ttslua | 1006 ++--- ...stom_Tile Blood on the Altar 92b54a.ttslua | 50 +- ...g 5 Undimensioned and Unseen afe7ce.ttslua | 1006 ++--- ...ile Undimensioned and Unseen 393c71.ttslua | 50 +- ...odel_Bag 6 Where Doom Awaits 022ddf.ttslua | 1006 ++--- ...ustom_Tile Where Doom Awaits a621ae.ttslua | 50 +- ...Bag 7 Lost in Time and Space 684060.ttslua | 1006 ++--- ..._Tile Lost in Time and Space 64a607.ttslua | 50 +- ... Dunwich Legacy Campaign Log 3f6ab6.ttslua | 1338 +++---- ...Model_Bag The Dunwich Legacy 5889dd.ttslua | 1004 ++--- ..._Model_Bag The Forgotten Age 03b888.ttslua | 1004 ++--- ..._Model_Bag The Forgotten Age 0bcf19.ttslua | 1004 ++--- ...odel_Bag 1 The Untamed Wilds e90956.ttslua | 1004 ++--- ...ustom_Tile The Forgotten Age e95200.ttslua | 40 +- ...odel_Bag 2 The Doom of Eztli 065ce1.ttslua | 1004 ++--- ...ustom_Tile The Doom of Eztli 294ec4.ttslua | 48 +- ..._Model_Bag 3 Threads of Fate 11f5c8.ttslua | 1004 ++--- .../Custom_Tile Threads of Fate 7a95f6.ttslua | 48 +- ...el_Bag 4 The Boundary Beyond 0ec59f.ttslua | 1004 ++--- ...tom_Tile The Boundary Beyond 010761.ttslua | 48 +- ...5 Heart of the Elders Part 1 2bfe00.ttslua | 1004 ++--- ...tom_Tile Heart of the Elders 493cb1.ttslua | 48 +- ...5 Heart of the Elders Part 2 5b2403.ttslua | 1004 ++--- ...l_Bag 6 The City of Archives 3170ce.ttslua | 1004 ++--- ...om_Tile The City of Archives 2fb6dc.ttslua | 48 +- ...del_Bag 7 The Depths of Yoth 85286a.ttslua | 1004 ++--- ...stom_Tile The Depths of Yoth 7aa4e3.ttslua | 48 +- ...oken Scenario - EasyStandard dd61f1.ttslua | 262 +- ..._Token Scenario - HardExpert 2da146.ttslua | 262 +- ..._Model_Bag 8 Shattered Aeons 737c5d.ttslua | 1004 ++--- .../Custom_Tile Shattered Aeons 6dc72a.ttslua | 42 +- ..._Model_Bag 9 Secret Scenario c52079.ttslua | 1004 ++--- ...e Forgotten Age Campaign Log 48b154.ttslua | 1380 +++---- ...Bag The Innsmouth Conspiracy 10bd18.ttslua | 1004 ++--- ...Bag The Innsmouth Conspiracy 465aab.ttslua | 1004 ++--- ...del_Bag 1 The Pit of Despair c09838.ttslua | 1006 ++--- ...ile The Innsmouth Conspiracy 16562e.ttslua | 42 +- ...he Vanishing of Elina Harper 8c6d05.ttslua | 1006 ++--- ...stom_Model_Bag 3 In Too Deep c3a225.ttslua | 1006 ++--- .../Custom_Tile In Too Deep bbb70a.ttslua | 50 +- ...outh Conspiracy Campaign Log f40183.ttslua | 1336 +++---- ...odel_Bag The Path to Carcosa 899c3a.ttslua | 1004 ++--- ...odel_Bag The Path to Carcosa aca04c.ttslua | 1004 ++--- ...tom_Model_Bag 1 Curtain Call 83ccd4.ttslua | 546 +-- ...tom_Tile The Path to Carcosa 16562e.ttslua | 42 +- ...om_Model_Bag 2 The Last King 6730a1.ttslua | 546 +-- .../Custom_Tile The Last King 857d0d.ttslua | 48 +- ...del_Bag 3 Echoes of the Past 42d2dc.ttslua | 546 +-- ...stom_Tile Echoes of the Past 452210.ttslua | 50 +- ...l_Bag 4 The Unspeakable Oath e7efa6.ttslua | 546 +-- ...om_Tile The Unspeakable Oath 87f45e.ttslua | 50 +- ...del_Bag 5 A Phantom of Truth bd4167.ttslua | 546 +-- ...stom_Tile A Phantom of Truth b20b8d.ttslua | 50 +- ..._Model_Bag 6 The Pallid Mask eb48ff.ttslua | 546 +-- .../Custom_Tile The Pallid Mask bb070d.ttslua | 50 +- ...Model_Bag 7 Black Stars Rise dd8b0d.ttslua | 546 +-- .../Bag Setup Bag b29b71.ttslua | 546 +-- .../Bag Setup Bag d14543.ttslua | 546 +-- ...Custom_Tile Black Stars Rise 20c21d.ttslua | 50 +- ...stom_Model_Bag 8 Dim Carcosa ce5d30.ttslua | 546 +-- .../Custom_Tile Dim Carcosa 9afdfd.ttslua | 50 +- ...om_Tile Carcosa Campaign Log ae8317.ttslua | 1510 ++++---- ..._Model_Bag The Side Missions 2d16e1.ttslua | 1004 ++--- ...odel_Bag Against the Wendigo 4d5fa0.ttslua | 546 +-- ...tom_Tile Against the Wendigo 82e1ed.ttslua | 40 +- ...odel_Bag Alice in Wonderland 39916d.ttslua | 1006 ++--- ...l_Bag 1 Arkham in Wonderland 18aa54.ttslua | 544 +-- ...el_Bag 2-A A Sea of Troubles 952572.ttslua | 544 +-- ..._Bag 2-B Tempest in a Teapot 8d88c8.ttslua | 544 +-- ...odel_Bag 2-C Bleeding Hearts 8eb793.ttslua | 544 +-- ...del_Bag 2-D Wild Snark Chase 9e33a0.ttslua | 544 +-- ...odel_Bag 2-E Sibling Rivalry 0916b6.ttslua | 544 +-- ...om_Model_Bag 2-F Fool's Mate bd556e.ttslua | 544 +-- ..._Model_Bag 3 Lucid Nightmare e6bb63.ttslua | 544 +-- ...tom_Tile Alice in Wonderland b5928a.ttslua | 42 +- ...e in Wonderland Campaign Log eda22b.ttslua | 1302 +++---- ...tom_Model_Bag All or Nothing 72ab92.ttslua | 1006 ++--- .../Bag With Return Set 083fc2.ttslua | 546 +-- .../Bag Without Return Set d14543.ttslua | 546 +-- .../Custom_Tile All or Nothing b5928a.ttslua | 42 +- ...l_Bag Blood Spilled in Salem 4237da.ttslua | 546 +-- ..._Tile Blood Spilled in Salem 83b781.ttslua | 40 +- ...om_Model_Bag Bridge of Sighs 578e97.ttslua | 546 +-- .../Custom_Tile Bridge of Sighs 2d9794.ttslua | 40 +- ...del_Bag Carnevale of Horrors 23dd51.ttslua | 1006 ++--- ...om_Tile Carnevale of Horrors a5891b.ttslua | 26 +- ...del_Bag Carnevale of Spiders e57017.ttslua | 546 +-- .../Bag Atlach-Nacha d14543.ttslua | 546 +-- ...om_Tile Carnevale of Spiders a5891b.ttslua | 26 +- ...rnation on the Constellation 0ec730.ttslua | 546 +-- .../Bag Additional locations d14543.ttslua | 546 +-- ...rnation on the Constellation bbb70a.ttslua | 50 +- ...el_Bag Curse of the Rougarou db7039.ttslua | 1006 ++--- .../Bag Locations 73e53d.ttslua | 10 +- ...m_Tile Curse of the Rougarou cf0c00.ttslua | 26 +- ...Custom_Model_Bag Dark Matter 7458b7.ttslua | 1006 ++--- ...rk Matter Custom Data Helper a57738.ttslua | 166 +- ...Model_Bag Electric Nightmare 2bd90b.ttslua | 1006 ++--- ...odel_Bag Fragment of Carcosa a492bc.ttslua | 1006 ++--- ...l_Bag In the Shadow of Earth 8cfe99.ttslua | 1006 ++--- ...ustom_Model_Bag Lost Quantum c29a78.ttslua | 1006 ++--- .../Custom_Model_Bag Starfall e04c21.ttslua | 1006 ++--- ...stom_Model_Bag Strange Moons 2ebcda.ttslua | 1006 ++--- ...el_Bag The Machine in Yellow 32039e.ttslua | 1006 ++--- ..._Model_Bag The Tatteremalion 51fbbc.ttslua | 1006 ++--- .../Custom_Tile 0aa185.ttslua | 1472 ++++---- .../Custom_Tile Dark Matter b5928a.ttslua | 42 +- .../Custom_Token Memories 13bc7d.ttslua | 260 +- .../Custom_Token Memories 66dad0.ttslua | 260 +- .../Custom_Token Memories 794376.ttslua | 260 +- .../Custom_Token Memories 99db87.ttslua | 260 +- ...tom_Model_Bag Darkness Falls c6a612.ttslua | 1004 ++--- .../Custom_Tile Darkness Falls b5928a.ttslua | 42 +- ..._Bag Delta Green Convergence ac164e.ttslua | 546 +-- ..._Tile Delta Geen Convergence 520889.ttslua | 40 +- ...om_Model_Bag Flesh and Blood 613b64.ttslua | 1006 ++--- ...ustom_Model_Bag Dead by Dawn c29a78.ttslua | 1006 ++--- ...Custom_Model_Bag Late Risers 51fbbc.ttslua | 1006 ++--- ...om_Model_Bag Mourning Chorus 24c385.ttslua | 1006 ++--- ..._Model_Bag Night on the Town 2bd90b.ttslua | 1006 ++--- .../Custom_Tile Flesh and Blood ac895d.ttslua | 42 +- .../Custom_Tile Flesh and Blood f5db25.ttslua | 42 +- ...m_Token Generic Campaign Log eda22b.ttslua | 1302 +++---- ...l_Bag Guardians of the Abyss ee987d.ttslua | 546 +-- ...odel_Bag The Eternal Slumber 9ff406.ttslua | 546 +-- ...oken Scenario - EasyStandard b7af99.ttslua | 262 +- ...oken Scenario - EasyStandard e19c97.ttslua | 262 +- ...odel_Bag The Night's Usurper 578bcb.ttslua | 546 +-- ...oken Scenario - EasyStandard afc7b5.ttslua | 262 +- ..._Token Scenario - HardExpert 9ed124.ttslua | 262 +- ..._Tile Guardians of the Abyss 82e1ed.ttslua | 42 +- ...m_Model_Bag Happy's Funhouse e7d9f8.ttslua | 546 +-- ...Custom_Tile Happy's Funhouse c5008a.ttslua | 40 +- ...stom_Model_Bag Idol Thoughts 2d417b.ttslua | 544 +-- ...del_Bag 1 Bread and Circuses 16ceab.ttslua | 546 +-- ...Model_Bag 2 Enter the Dragon 4f944f.ttslua | 546 +-- ...ustom_Model_Bag 3 Bon Voyage 49dfb9.ttslua | 546 +-- ...om_Model_Bag 4 Cost of Azure 0fad66.ttslua | 546 +-- ...stom_Tile Bread and Circuses 82e1ed.ttslua | 40 +- ...m_Model_Bag In Blackest Pits 68380c.ttslua | 544 +-- .../Custom_Tile The Initiation bbb70a.ttslua | 50 +- ...del_Bag Into the Shadowlands 019847.ttslua | 546 +-- .../Bag 1 Dark Reflections c1aad0.ttslua | 546 +-- ...om_Tile Into the Shadowlands 770021.ttslua | 42 +- .../Bag 2 Endless Horizons b1bc62.ttslua | 546 +-- ...tom_Model_Bag Jenny's Choice a61b48.ttslua | 546 +-- .../Custom_Tile Jenny's Choice bbb70a.ttslua | 50 +- ...stom_Model_Bag Kaimonogatari 2df25a.ttslua | 1006 ++--- ...stom_Model_Bag Investigators fba392.ttslua | 1006 ++--- ...odel_Bag Izanami's Delegates b34bec.ttslua | 1006 ++--- ...ustom_Model_Bag Player Cards 64ad17.ttslua | 1006 ++--- ...cenario 1 - Modorimonogatari f051fc.ttslua | 1006 ++--- ...cenario 2A - Toshimonogatari 4076cd.ttslua | 1006 ++--- ...cenario 2B - Inarimonogatari ad56f2.ttslua | 1006 ++--- ...io 2S - Shinkansenmonogatari 8221db.ttslua | 1006 ++--- ...atari first, choose this bag 1a6190.ttslua | 1094 +++--- ...atari first, choose this bag 91392f.ttslua | 1094 +++--- ... Scenario 3 - Yamamonogatari b99de3.ttslua | 1006 ++--- ...cenario 4 - Houkaimonogatari 8f297e.ttslua | 1006 ++--- ...Scenario 5 - Fumeimonogatari b86938.ttslua | 1006 ++--- .../Custom_Tile Kaimonogatari f5db25.ttslua | 42 +- ...oken Monogatari Campaign Log eda22b.ttslua | 1280 +++---- ...y sny Stają się Rzeczywiścią acdf16.ttslua | 546 +-- ...iwny Przypadek Benedicta Burtona bd069f.ttslua | 546 +-- .../Bag Nieuchwytny 31a93a.ttslua | 546 +-- .../Bag Podniebny Koncert 2889f0.ttslua | 546 +-- .../Bag Przeznacznenie w Red Hook 1e00a9.ttslua | 546 +-- .../Custom_Model_Bag Knightfall df62e8.ttslua | 546 +-- .../Custom_Tile Knightfall 271ce2.ttslua | 40 +- ...del_Bag Last Call at Roxie's c6a1ca.ttslua | 546 +-- ...om_Tile Last Call at Roxie's 567db0.ttslua | 40 +- ...s of Nyarlathotep – New York 94a1f8.ttslua | 546 +-- .../Custom_Tile Core Difficulty aae2b1.ttslua | 40 +- ...urder at the Excelsior Hotel 01d780.ttslua | 1006 ++--- ...urder at the Excelsior Hotel bbb70a.ttslua | 50 +- ...odel_Bag North Country Cycle aaceca.ttslua | 546 +-- .../Bag Part 1 147dea.ttslua | 546 +-- .../Bag Part 2 7f9f0d.ttslua | 546 +-- .../Bag Part 3 df5156.ttslua | 546 +-- .../Custom_Tile Core Difficulty ea0896.ttslua | 40 +- ...odel_Bag Of Sphinx and Sands eeeb50.ttslua | 544 +-- .../Bag 1 Eye on the Prize e54f2a.ttslua | 544 +-- .../Custom_Tile Core Difficulty 56a08b.ttslua | 42 +- .../Bag 2 Chaos in Cairo 6e0236.ttslua | 544 +-- .../Bag 3 The Will to Triump 6d8dad.ttslua | 544 +-- ...del_Bag Ordo Templi Orientis 7cf202.ttslua | 544 +-- .../Bag Midnight in Paris 7cda3f.ttslua | 1008 ++--- .../Bag Shadows of Brocéliande 7b28eb.ttslua | 1008 ++--- .../Bag The München Conspiracy 286579.ttslua | 1008 ++--- .../Bag Tibetan Winds ba2ded.ttslua | 1008 ++--- ...om_Tile Ordo Templi Orientis bbb70a.ttslua | 48 +- ..._Model_Bag Parallel Universe 28e0a1.ttslua | 546 +-- .../Bag c0897e.ttslua | 546 +-- .../Bag 1 Nightmare or Dream f39e68.ttslua | 546 +-- .../Bag 2 Awake 6ca52c.ttslua | 546 +-- .../Custom_Tile Core Difficulty 56a08b.ttslua | 40 +- ...Bag Pokemon Eldritch Edition 75fe78.ttslua | 1004 ++--- ...emon To An Existing Campaign 7b57ad.ttslua | 546 +-- .../Bag Basic Pokemon d14543.ttslua | 546 +-- .../Bag Pokemon Investigators 05109d.ttslua | 546 +-- ...Bag Scenario 1 The Conjuring e1caf1.ttslua | 546 +-- ...ile Pokemon Eldritch Edition 3837a5.ttslua | 40 +- ...Scenario 2a The Winding Road 61801e.ttslua | 546 +-- ...b Shipments From The Unknown 13ed7d.ttslua | 546 +-- .../Bag Scenario 3a Viridian f040a6.ttslua | 546 +-- ...Bag Scenario 3b Deep Secrets 3da6dd.ttslua | 546 +-- ...g Scenario 4 The Unconjuring 52d102.ttslua | 546 +-- ...Side-Story 1 Eldritch Safari 1fae15.ttslua | 546 +-- .../Custom_Tile Eldritch Safari 3837a5.ttslua | 40 +- ...ide-Story 2 Project Cerulean 4c07bf.ttslua | 546 +-- ...Custom_Tile Project Cerulean 3837a5.ttslua | 40 +- .../Bag Upgrade Pokemon 2cea4e.ttslua | 546 +-- .../Custom_Token Campaign Log eda22b.ttslua | 1302 +++---- ...Custom_Model_Bag Read or Die 9e73fa.ttslua | 1006 ++--- .../Custom_Tile Read or Die b5928a.ttslua | 42 +- ...stom_Model_Bag Strange Aeons 2abdd6.ttslua | 546 +-- .../Bag 1 In Search Of Sanity 961940.ttslua | 546 +-- .../Bag 2 The Thrushmoor Terror eea51b.ttslua | 546 +-- .../Custom_Tile Strange Aeons 82e1ed.ttslua | 42 +- ...om_Model_Bag Stranger Things 408301.ttslua | 546 +-- .../Custom_Tile Stranger Things bc825a.ttslua | 40 +- ...el_Bag The Approaching Storm 0fad66.ttslua | 546 +-- .../Bag 1 Plot Uncovered 67d524.ttslua | 546 +-- .../Bag 2 Dark Waters 90aab1.ttslua | 546 +-- .../Bag 3 Curiosities 20982e.ttslua | 546 +-- .../Bag 4 Shadow Rails 3a3b5a.ttslua | 546 +-- .../Bag 5 lair of the Cult 266dcb.ttslua | 546 +-- .../Bag 6 Domain of Baal 84cdaf.ttslua | 546 +-- ...m_Tile The Approaching Storm 7521a9.ttslua | 40 +- ...The Blob that Ate Everything 4dee5a.ttslua | 1004 ++--- .../Bag Epic Multiplayer 2c10cf.ttslua | 546 +-- .../Bag Single Group 830305.ttslua | 546 +-- ...The Blob that Ate Everything bbb70a.ttslua | 48 +- ...stom_Model_Bag The Collector 9810eb.ttslua | 546 +-- .../Custom_Tile The Collector 150603.ttslua | 40 +- ..._Bag The Colour out of Space 5b81ff.ttslua | 546 +-- ...Tile The Colour out of Space 2e887e.ttslua | 40 +- ...el_Bag The Curse of Amulotep 0d7a8d.ttslua | 546 +-- ...om_Tile The Curse of Amultep b3cbc1.ttslua | 40 +- ...tom_Model_Bag The Dying Star bcfff6.ttslua | 546 +-- .../Bag Part 1 b310b9.ttslua | 546 +-- .../Custom_Tile The Dying Star 8d62ae.ttslua | 40 +- .../Bag Part 2 c2a55d.ttslua | 546 +-- .../Custom_Tile The Dying Star a148f2.ttslua | 40 +- ...ustom_Model_Bag The Festival 29d22a.ttslua | 546 +-- .../Custom_Tile The Festival 4b81f6.ttslua | 40 +- ...odel_Bag The Grand Oak Hotel 4255b1.ttslua | 546 +-- .../Custom_Tile Core Difficulty 9cd1ad.ttslua | 40 +- ...Bag The Labyrinths of Lunacy 4c173f.ttslua | 546 +-- .../Bag Epic Group A 79b534.ttslua | 546 +-- .../Bag Epic Group B c7c4c1.ttslua | 546 +-- .../Bag Epic Group C c352ac.ttslua | 546 +-- .../Bag Single Group A 2ea2a2.ttslua | 546 +-- .../Bag Single Group B 14808b.ttslua | 546 +-- .../Bag Single Group C 76b476.ttslua | 546 +-- ...ile The Labyrinths of Lunacy f4dcee.ttslua | 42 +- ... The Legend of Sleepy Hollow b46db2.ttslua | 1006 ++--- ... The Legend of Sleepy Hollow bbb70a.ttslua | 24 +- ...m_Token Generic Campaign Log eda22b.ttslua | 1018 ++--- ...tom_Model_Bag The London Set 0f96ac.ttslua | 546 +-- .../Bag 1 A Loving Spouse 4c5c55.ttslua | 546 +-- .../Custom_Tile A Loving Spouse ea41d9.ttslua | 42 +- .../Bag 2 Mrs Tillywingers Cat c56f66.ttslua | 546 +-- ...om_Tile Mrs Tillywingers Cat 0ae91a.ttslua | 42 +- ... 3 Disgracing Alderman Whitn 905ad3.ttslua | 546 +-- ... Disgracing Alderman Whitney c2736e.ttslua | 42 +- ...m_Model_Bag The Nephew Calls 3ddd12.ttslua | 546 +-- ...Custom_Tile The Nephew Calls 54707a.ttslua | 40 +- ...ustom_Model_Bag The Outsider 3c175c.ttslua | 546 +-- .../Bag Part 1 526ff9.ttslua | 546 +-- .../Bag Part 2 5b3ac7.ttslua | 546 +-- .../Bag Part 3 d166f2.ttslua | 546 +-- .../Custom_Tile The Outsider d5b06c.ttslua | 40 +- ...m_Model_Bag The Pensher Wyrm 504f38.ttslua | 546 +-- ...Custom_Tile The Pensher Wyrm c606a1.ttslua | 42 +- ...ustom_Model_Bag The Red Room fa4327.ttslua | 546 +-- ...odel_Bag The Stolen Baillius bfefd4.ttslua | 546 +-- .../Custom_Tile Core Difficulty ec7a73.ttslua | 40 +- ...Model_Bag The Svalbard Event 7bc42b.ttslua | 546 +-- .../Custom_Tile Core Difficulty a751fe.ttslua | 40 +- ...g The Symphony of Erich Zann b7c6be.ttslua | 1004 ++--- ...tom_Model Custom Data Helper c0b834.ttslua | 74 +- ...e The Symphony of Erich Zann f4c93e.ttslua | 50 +- ...l_Bag The Thing in the Woods c90c49.ttslua | 546 +-- .../Custom_Tile Core Difficulty 2261a5.ttslua | 40 +- ...el_Bag The War of the Worlds 19d469.ttslua | 1004 ++--- ...om_Model_Bag 1 First Contact f70a0d.ttslua | 544 +-- ...odel_Bag 2 Phobos and Deimos 313523.ttslua | 544 +-- ...del_Bag 3 The Thirsting Void a0d2b1.ttslua | 544 +-- ...ustom_Tile War of the Worlds b5928a.ttslua | 40 +- ...r of the Worlds Campaign Log eda22b.ttslua | 1362 +++---- ...ustom_Model_Bag Winter Winds 754057.ttslua | 546 +-- .../Bag Frozen Tracks 11429d.ttslua | 546 +-- .../Bag Stranded in the Urals 8077a1.ttslua | 546 +-- .../Bag The Forgotten Village ddd10b.ttslua | 546 +-- .../Custom_Tile Winter Winds d54710.ttslua | 40 +- ...tom_Model_Bag Weakness decks 750fdd.ttslua | 1004 ++--- ...tom_Model_Bag Weakness decks ceacbf.ttslua | 1004 ++--- .../Custom_Tile Data Helper 708279.ttslua | 3358 ++++++++--------- .../Custom_Tile Deck Importer 928c8e.ttslua | 1146 +++--- ...ustom_Tile Playermat 1 White 8b081b.ttslua | 808 ++-- ...stom_Tile Playermat 2 Orange bd0ff4.ttslua | 808 ++-- ...ustom_Tile Playermat 3 Green 383d8b.ttslua | 808 ++-- .../Custom_Tile Playermat 4 Red 0840d5.ttslua | 808 ++-- unpacked/Custom_Token b7b45b.ttslua | 396 +- .../Custom_Token Agenda Deck 85c4c6.ttslua | 262 +- ...Token Chaos Bag Stat Tracker 766620.ttslua | 200 +- unpacked/Custom_Token Damage 1f5a0a.ttslua | 260 +- unpacked/Custom_Token Damage 591a45.ttslua | 260 +- unpacked/Custom_Token Damage e64eec.ttslua | 260 +- unpacked/Custom_Token Damage eb08d6.ttslua | 260 +- unpacked/Custom_Token Horror 0257d9.ttslua | 260 +- unpacked/Custom_Token Horror 468e88.ttslua | 260 +- unpacked/Custom_Token Horror 7b5729.ttslua | 260 +- unpacked/Custom_Token Horror beb964.ttslua | 260 +- ...om_Token Master Clue Counter 4a3aa4.ttslua | 310 +- unpacked/Custom_Token Playarea 721ba2.ttslua | 426 +-- unpacked/Custom_Token Resources 4406f0.ttslua | 260 +- unpacked/Custom_Token Resources 816d84.ttslua | 260 +- unpacked/Custom_Token Resources a4b60d.ttslua | 260 +- unpacked/Custom_Token Resources cd15ac.ttslua | 260 +- 511 files changed, 141089 insertions(+), 141089 deletions(-) diff --git a/unpacked.ttslua b/unpacked.ttslua index d627daaf2..bf9ff0cf1 100644 --- a/unpacked.ttslua +++ b/unpacked.ttslua @@ -1,742 +1,742 @@ ---[[ Lua code. See documentation: http://berserk-games.com/knowledgebase/scripting/ --]] --- Card size used for autodealing -- - --- global position constants -ENCOUNTER_DECK_POS = {-3.8, 1, 5.7} -ENCOUNTER_DECK_SPAWN_POS = {-3.8, 3, 5.7} -ENCOUNTER_DECK_DISCARD_POSITION = {-3.8, 0.5, 10.5} -g_cardWith=2.30; -g_cardHeigth=3.40; - -containerId = 'fea079' -tokenDataId = '708279' - - -CACHE = { - object = {}, - data = {} -} - ---[[ The OnLoad function. This is called after everything in the game save finishes loading. -Most of your script code goes here. --]] -function onload() - --Player.White.changeColor('Yellow') - tokenplayerone = { - damageone = "https://i.imgur.com/XIJHw3J.png", - damagethree = "https://i.imgur.com/eqRC712.png", - horrorone = "https://i.imgur.com/Bh0BO47.png", - horrorthree = "https://i.imgur.com/pZvTKA7.png", - resource = "https://i.imgur.com/j5v5E3j.png", - resourcethree = "https://i.imgur.com/1GZsDTt.png", - doom = "https://i.imgur.com/EoL7yaZ.png", - clue = "https://i.imgur.com/wfCaVU0.png" - } - - TOKEN_DATA = { - clue = {image = tokenplayerone.clue, scale = {0.15, 0.15, 0.15}}, - resource = {image = tokenplayerone.resource, scale = {0.17, 0.17, 0.17}}, - doom = {image = tokenplayerone.doom, scale = {0.17, 0.17, 0.17}} - } - - getObjectFromGUID("6161b4").interactable=false - getObjectFromGUID("721ba2").interactable=false - getObjectFromGUID("9f334f").interactable=false - getObjectFromGUID("23a43c").interactable=false - getObjectFromGUID("5450cc").interactable=false - getObjectFromGUID("463022").interactable=false - getObjectFromGUID("9487a4").interactable=false - getObjectFromGUID("91dd9b").interactable=false - getObjectFromGUID("f182ee").interactable=false - -end - -function take_callback(object_spawned, mat) - customObject = object_spawned.getCustomObject() - local player = mat.getGUID(); - - local image = customObject.image - - -- Update global stats - if PULLS[image] == nil then - PULLS[image] = 0 - end - PULLS[image] = PULLS[image] + 1 - -- Update player stats - if PLAYER_PULLS[player][image] == nil then - PLAYER_PULLS[player][image] = 0 - end - PLAYER_PULLS[player][image] = PLAYER_PULLS[player][image] + 1 - -end -MAT_GUID_TO_COLOUR = { - ["8b081b"] = "White", - -- player 2 conrad - ["bd0ff4"] = "Orange", - -- player - ["383d8b"] = "Green", - -- playur 4 olivia - ["0840d5"] = "Red" -} - - -PLAYER_PULLS = { - -- player 1 max - ["8b081b"] = {}, - -- player 2 conrad - ["bd0ff4"] = {}, - -- player - ["383d8b"] = {}, - -- playur 4 olivia - ["0840d5"] = {} -} - -PULLS = { - -- cultist - ["https://i.imgur.com/VzhJJaH.png"] = 0, - -- skull - ["https://i.imgur.com/stbBxtx.png"] = 0, - -- tablet - ["https://i.imgur.com/1plY463.png"] = 0, - -- curse - ["http://cloud-3.steamusercontent.com/ugc/1011565208488654691/8F0B399048EBC34CD24B99AAD415AEC40E679C65/"] = 0, - -- tentacle - ["https://i.imgur.com/lns4fhz.png"] = 0, - -- minus eight - ["https://i.imgur.com/9t3rPTQ.png"] = 0, - -- minus seven - ["https://i.imgur.com/4WRD42n.png"] = 0, - -- minus six - ["https://i.imgur.com/c9qdSzS.png"] = 0, - -- minus five - ["https://i.imgur.com/3Ym1IeG.png"] = 0, - -- minus four - ["https://i.imgur.com/qrgGQRD.png"] = 0, - -- minus three - ["https://i.imgur.com/yfs8gHq.png"] = 0, - -- minus two - ["https://i.imgur.com/bfTg2hb.png"] = 0, - -- minus one - ["https://i.imgur.com/w3XbrCC.png"] = 0, - -- zero - ["https://i.imgur.com/btEtVfd.png"] = 0, - -- plus one - ["https://i.imgur.com/uIx8jbY.png"] = 0, - -- elder thing - ["https://i.imgur.com/ttnspKt.png"] = 0, - -- bless - ["http://cloud-3.steamusercontent.com/ugc/1011565208488650618/B2B081032AF3EFDBD90840A5D6888A3CEA228D66/"] = 0, - -- elder sign - ["https://i.imgur.com/nEmqjmj.png"] = 0, -} - -IMAGE_TOKEN_MAP = { - -- cultist - ["https://i.imgur.com/VzhJJaH.png"] = "cultist", - -- skull - ["https://i.imgur.com/stbBxtx.png"] = "skull", - -- tablet - ["https://i.imgur.com/1plY463.png"] = "tablet", - -- elder thing - ["https://i.imgur.com/ttnspKt.png"] = "Elder Thing", - -- curse - ["http://cloud-3.steamusercontent.com/ugc/1011565208488654691/8F0B399048EBC34CD24B99AAD415AEC40E679C65/"] = "curse", - -- tentacle - ["https://i.imgur.com/lns4fhz.png"] = "Auto-Fail", - -- minus eight - ["https://i.imgur.com/9t3rPTQ.png"] = "-8", - -- minus seven - ["https://i.imgur.com/4WRD42n.png"] = "-7", - -- minus six - ["https://i.imgur.com/c9qdSzS.png"] = "-6", - -- minus five - ["https://i.imgur.com/3Ym1IeG.png"] = "-5", - -- minus four - ["https://i.imgur.com/qrgGQRD.png"] = "-4", - -- minus three - ["https://i.imgur.com/yfs8gHq.png"] = "-3", - -- minus two - ["https://i.imgur.com/bfTg2hb.png"] = "-2", - -- minus one - ["https://i.imgur.com/w3XbrCC.png"] = "-1", - -- zero - ["https://i.imgur.com/btEtVfd.png"] = "0", - -- plus one - ["https://i.imgur.com/uIx8jbY.png"] = "+1", - -- bless - ["http://cloud-3.steamusercontent.com/ugc/1011565208488650618/B2B081032AF3EFDBD90840A5D6888A3CEA228D66/"] = "bless", - -- elder sign - ["https://i.imgur.com/nEmqjmj.png"] = "Elder Sign", -} - -function resetStats() - for key,value in pairs(PULLS) do - PULLS[key] = 0 - end - for playerKey, playerValue in pairs(PLAYER_PULLS) do - for key,value in pairs(PULLS) do - PLAYER_PULLS[playerKey][key] = value - end - end - - -end - -function getPlayerName(playerMatGuid) - local playerColour = MAT_GUID_TO_COLOUR[playerMatGuid] - if Player[playerColour].seated then - return Player[playerColour].steam_name - else - return playerColour - end -end - -function printStats() - local squidKing = "Nobody" - local maxSquid = 0 - - printToAll("\nOverall Game stats\n") - printNonZeroTokenPairs(PULLS) - printToAll("\nIndividual Stats\n") - for playerMatGuid, countTable in pairs(PLAYER_PULLS) do - local playerName = getPlayerName(playerMatGuid) - printToAll(playerName .. " Stats", {r=255,g=0,b=0}) - printNonZeroTokenPairs(PLAYER_PULLS[playerMatGuid]) - playerSquidCount = PLAYER_PULLS[playerMatGuid]["https://i.imgur.com/lns4fhz.png"] - if playerSquidCount != nil and playerSquidCount > maxSquid then - squidKing = playerName - end - end - printToAll(squidKing .. " is an auto-fail magnet.", {r=255,g=0,b=0}) -end - -function printNonZeroTokenPairs(theTable) - for key,value in pairs(theTable) do - if value != 0 then - printToAll(IMAGE_TOKEN_MAP[key] .. '=' .. tostring(value)) - end - end -end - --- Remove comments to enable autorotate cards on hands. --- function onObjectEnterScriptingZone(zone, object) --- Autorotate cards with right side up when entering hand. --- if zone.getGUID() == "c506bf" or -- white --- zone.getGUID() == "cbc751" then -- orange --- object.setRotationSmooth({0,270,0}) --- elseif zone.getGUID() == "67ce9a" then -- green --- object.setRotationSmooth({0,0,0}) --- elseif zone.getGUID() == "57c22c" then -- red --- object.setRotationSmooth({0,180,0}) ---end ---end - -function findInRadiusBy(pos, radius, filter, debug) - local radius = (radius or 1) - local objList = Physics.cast({ - origin = pos, - direction = {0,1,0}, - type = 2, - size = {radius, radius, radius}, - max_distance = 0, - debug = (debug or false) - }) - - local filteredList = {} - for _, obj in ipairs(objList) do - if filter == nil then - table.insert(filteredList, obj.hit_object) - elseif filter and filter(obj.hit_object) then - table.insert(filteredList, obj.hit_object) - end - end - return filteredList -end - -function dealCardsInRows(paramlist) - local currPosition={}; - local numRow=1; - local numCard=0; - local invMultiplier=1; - local allCardsDealed=0; - if paramlist.inverse then - invMultiplier=-1; - end - if paramlist.maxCardsDealed==nil then - - allCardsDealed=0; - paramlist.maxCardsDealed=paramlist.cardDeck.getQuantity() - - elseif paramlist.maxCardsDealed>=paramlist.cardDeck.getQuantity() or paramlist.maxCardsDealed<=0 then - - allCardsDealed=0; - paramlist.maxCardsDealed=paramlist.cardDeck.getQuantity() - - else - - allCardsDealed=1; - - end - - if paramlist.mode=="x" then - currPosition={paramlist.iniPosition[1]+(2*g_cardWith*invMultiplier*allCardsDealed),paramlist.iniPosition[2],paramlist.iniPosition[3]}; - - else - currPosition={paramlist.iniPosition[1],paramlist.iniPosition[2],paramlist.iniPosition[3]+(2*g_cardWith*invMultiplier*allCardsDealed)}; - - end - - for i = 1,paramlist.maxCardsDealed,1 do - - paramlist.cardDeck.takeObject - ({ - position= currPosition, - smooth= true - }); - - numCard=numCard+1; - if numCard>=paramlist.maxCardRow then - - if paramlist.mode=="x" then - currPosition={paramlist.iniPosition[1]+(2*g_cardWith*invMultiplier*allCardsDealed),paramlist.iniPosition[2],paramlist.iniPosition[3]}; - currPosition[3]=currPosition[3]-(numRow*g_cardHeigth*invMultiplier); - else - currPosition={paramlist.iniPosition[1],paramlist.iniPosition[2],paramlist.iniPosition[3]+(2*g_cardWith*invMultiplier*allCardsDealed)}; - currPosition[1]=currPosition[1]+(numRow*g_cardHeigth*invMultiplier); - end - numCard=0; - numRow=numRow+1; - - else - if paramlist.mode=="x" then - currPosition[1]=currPosition[1]+(g_cardWith*invMultiplier); - else - currPosition[3]=currPosition[3]+(g_cardWith*invMultiplier); - end - end - end -end - -function isDeck(x) - return x.tag == 'Deck' -end - -function isCardOrDeck(x) - return x.tag == 'Card' or isDeck(x) -end - -function drawEncountercard(params) --[[ Parameter Table Position, Table Rotation]] - local position = params[1] - local rotation = params[2] - local isFaceUp = params[3] - local faceUpRotation - if (isFaceUp) then - faceUpRotation = 0 - else - faceUpRotation = 180 - end - local items = findInRadiusBy(ENCOUNTER_DECK_POS, 4, isCardOrDeck) - if #items > 0 then - for i, v in ipairs(items) do - if v.tag == 'Deck' then - v.takeObject({index = 0, position = position, rotation = {0,rotation.y,faceUpRotation}}) - return - end - end --- we didn't find the deck so just pull the first thing we did find - items[1].setPositionSmooth(position, false, false) - items[1].setRotationSmooth({0,rotation.y,faceUpRotation}, false, false) - return - end --- nothing here, time to reshuffle - reshuffleEncounterDeck(position, {0,rotation.y,faceUpRotation}) -end - -IS_RESHUFFLING = false -function reshuffleEncounterDeck(position, rotation) - -- finishes moving the deck back and draws a card - local function move(deck) - deck.setPositionSmooth(ENCOUNTER_DECK_SPAWN_POS, true, false) - deck.takeObject({index = 0, position = position, rotation = rotation, flip = false}) - Wait.time(function() IS_RESHUFFLING = false end, 1) - end - -- bail out if we're mid reshuffle - if IS_RESHUFFLING then - return - end - local discarded = findInRadiusBy(ENCOUNTER_DECK_DISCARD_POSITION, 4, isDeck) - if #discarded > 0 then - IS_RESHUFFLING = true - local deck = discarded[1] - if not deck.is_face_down then - deck.flip() - end - deck.shuffle() - Wait.time(|| move(deck), 0.3) - else - printToAll("couldn't find encounter discard pile to reshuffle", {1, 0, 0}) - end -end - -CHAOS_TOKENS = {} -CHAOS_TOKENS_LAST_MAT = nil -function putBackChaosTokens() - local chaosbagposition = chaosbag.getPosition() - for k, token in pairs(CHAOS_TOKENS) do - if token != nil then - chaosbag.putObject(token) - token.setPosition({chaosbagposition[1],chaosbagposition[2]+0.5,chaosbagposition[3]}) - end - end - CHAOS_TOKENS = {} - end - -function drawChaostoken(params) - local mat = params[1] - local tokenOffset = params[2] - local isRightClick = params[3] - local isSameMat = (CHAOS_TOKENS_LAST_MAT == nil or CHAOS_TOKENS_LAST_MAT == mat) - if not isSameMat then - putBackChaosTokens() - end - CHAOS_TOKENS_LAST_MAT = mat - -- if we have left clicked and have no tokens OR if we have right clicked - if isRightClick or #CHAOS_TOKENS == 0 then - local items = getObjectFromGUID("83ef06").getObjects() - for i,v in ipairs(items) do - if items[i].getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(items[i].getGUID()) - break - end - end - -- bail out if we have no tokens - if #chaosbag.getObjects() == 0 then - return - end - chaosbag.shuffle() - -- add the token to the list, compute new position based on list length - tokenOffset[1] = tokenOffset[1] + (0.17 * #CHAOS_TOKENS) - local toPosition = mat.positionToWorld(tokenOffset) - local token = chaosbag.takeObject({ - index = 0, - position = toPosition, - rotation = mat.getRotation(), - callback_function = function(obj) take_callback(obj, mat) end - }) - CHAOS_TOKENS[#CHAOS_TOKENS + 1] = token - return - else - putBackChaosTokens() - end -end - -function spawnToken(params) - -- Position to spawn, - -- rotation vector to apply - -- translation vector to apply - -- token type - local position = params[1] - local tokenType = params[2] - local tokenData = TOKEN_DATA[tokenType] - if tokenData == nil then - error("no token data found for '" .. tokenType .. "'") - end - - local token = spawnObject({ - type = 'Custom_Token', - position = position, - rotation = {x=0, y=270, z=0} - }) - token.setCustomObject({ - image = tokenData['image'], - thickness = 0.3, - merge_distance = 5.0, - stackable = true, - }) - token.use_snap_points=false - token.scale(tokenData['scale']) - return token -end - -function round(params) -- Parameter (int number, int numberDecimalPlaces) - return tonumber(string.format("%." .. (params[2] or 0) .. "f", params[1])) -end - -function roundposition(params) -- Parameter (Table position) - return {round({params[1], 2}),round({params[2], 2}),round({params[3], 2})} -end - -function isEqual(params) --Parameter (Table table1, Table table2) returns true if the tables are equal - if params[1][1] == params[2][1] and params[1][2] == params[2][2] and params[1][3] == params[2][3] then - return true - else - return false - end -end - -function isFaceup(params) --Object object - if params.getRotation()[3] > -5 and params.getRotation()[3] < 5 then - return true - else - return false - end -end - ---Difficulty selector script - -function createSetupButtons(args) - local data = getDataValue('modeData', args.key) - if data ~= nil then - local z = -0.15 - if data.easy ~= nil then - args.object.createButton({ - label = 'Easy', - click_function = 'easyClick', - function_owner = args.object, - position = {0, 0.1, z}, - rotation = {0, 0, 0}, - scale = {0.47, 1, 0.47}, - height = 200, - width = 1150, - font_size = 100, - color = {0.87, 0.8, 0.70}, - font_color = {0, 0, 0} - }) - z = z + 0.20 - end - if data.normal ~= nil then - args.object.createButton({ - label = 'Standard', - click_function = 'normalClick', - function_owner = args.object, - position = {0, 0.1, z}, - rotation = {0, 0, 0}, - scale = {0.47, 1, 0.47}, - height = 200, - width = 1150, - font_size = 100, - color = {0.87, 0.8, 0.70}, - font_color = {0, 0, 0} - }) - z = z + 0.20 - end - if data.hard ~= nil then - args.object.createButton({ - label = 'Hard', - click_function = 'hardClick', - function_owner = args.object, - position = {0, 0.1, z}, - rotation = {0, 0, 0}, - scale = {0.47, 1, 0.47}, - height = 200, - width = 1150, - font_size = 100, - color = {0.87, 0.8, 0.70}, - font_color = {0, 0, 0} - }) - z = z + 0.20 - end - if data.expert ~= nil then - args.object.createButton({ - label = 'Expert', - click_function = 'expertClick', - function_owner = args.object, - position = {0, 0.1, z}, - rotation = {0, 0, 0}, - scale = {0.47, 1, 0.47}, - height = 200, - width = 1150, - font_size = 100, - color = {0.87, 0.8, 0.70}, - font_color = {0, 0, 0} - }) - z = z + 0.20 - end - z = z + 0.10 - if data.standalone ~= nil then - args.object.createButton({ - label = 'Standalone', - click_function = 'standaloneClick', - function_owner = args.object, - position = {0, 0.1, z}, - rotation = {0, 0, 0}, - scale = {0.47, 1, 0.47}, - height = 200, - width = 1150, - font_size = 100, - color = {0.87, 0.8, 0.70}, - font_color = {0, 0, 0} - }) - end - end -end - -function fillContainer(args) - local container = getObjectCache(containerId) - - if container ~= nil then - local data = getDataValue('modeData', args.key) - if data == nil then return end - - local value = data[args.mode] - if value == nil or value.token == nil then return end - - local pos = container.getPosition() - if args.object ~= nil then - pos = args.object.getPosition() - end - - cleanContainer(container) - - for _, token in ipairs(value.token) do - local obj = spawnToken_2(token, pos) - if obj ~= nil then - container.putObject(obj) - end - end - - if value.append ~= nil then - for _, token in ipairs(value.append) do - local obj = spawnToken_2(token, pos) - if obj ~= nil then - container.putObject(obj) - end - end - end - - if value.random then - local n = #value.random - if n > 0 then - for _, token in ipairs(value.random[getRandomCount(n)]) do - local obj = spawnToken_2(token, pos) - if obj ~= nil then - container.putObject(obj) - end - end - end - end - - if value.message then - broadcastToAll(value.message) - end - if value.warning then - broadcastToAll(value.warning, { 1, 0.5, 0.5 }) - end - end -end - -function spawnToken_2(id, pos) - local url = getImageUrl(id) - if url ~= '' then - local obj = spawnObject({ - type = 'Custom_Tile', - position = {pos.x, pos.y + 3, pos.z}, - rotation = {x = 0, y = 260, z = 0} - }) - obj.setCustomObject({ - type = 2, - image = url, - thickness = 0.10, - }) - obj.scale {0.81, 1, 0.81} - return obj - end -end - -function getImageUrl(id) - if id == 'p1' then return 'https://i.imgur.com/uIx8jbY.png' end - if id == '0' then return 'https://i.imgur.com/btEtVfd.png' end - if id == 'm1' then return 'https://i.imgur.com/w3XbrCC.png' end - if id == 'm2' then return 'https://i.imgur.com/bfTg2hb.png' end - if id == 'm3' then return 'https://i.imgur.com/yfs8gHq.png' end - if id == 'm4' then return 'https://i.imgur.com/qrgGQRD.png' end - if id == 'm5' then return 'https://i.imgur.com/3Ym1IeG.png' end - if id == 'm6' then return 'https://i.imgur.com/c9qdSzS.png' end - if id == 'm7' then return 'https://i.imgur.com/4WRD42n.png' end - if id == 'm8' then return 'https://i.imgur.com/9t3rPTQ.png' end - if id == 'skull' then return 'https://i.imgur.com/stbBxtx.png' end - if id == 'cultist' then return 'https://i.imgur.com/VzhJJaH.png' end - if id == 'tablet' then return 'https://i.imgur.com/1plY463.png' end - if id == 'elder' then return 'https://i.imgur.com/ttnspKt.png' end - if id == 'red' then return 'https://i.imgur.com/lns4fhz.png' end - if id == 'blue' then return 'https://i.imgur.com/nEmqjmj.png' end - return '' -end - -function cleanContainer(container) - for _, item in ipairs(container.getObjects()) do - destroyObject(container.takeObject({})) - end -end - -function getObjectsInZone(zoneId) - local zoneObject = getObjectCache(zoneId) - - if zoneObject == nil then - return - end - - local objectsInZone = zoneObject.getObjects() - local objectsFound = {} - - for i = 1, #objectsInZone do - local object = objectsInZone[i] - if object.tag == 'Bag' then - table.insert(objectsFound, object.guid) - end - end - - if #objectsFound > 0 then - return objectsFound - end -end - -function getObjectCache(id) - if CACHE.object[id] == nil then - CACHE.object[id] = getObjectFromGUID(id) - end - return CACHE.object[id] -end - -function getDataTable(storage) - if CACHE.data[storage] == nil then - local obj = getObjectCache(tokenDataId) - if obj ~= nil then - CACHE.data[storage] = obj.getTable(storage) - end - end - return CACHE.data[storage] -end - -function getDataValue(storage, key) - local data = getDataTable(storage) - if data ~= nil then - local value = data[key] - if value ~= nil then - local res = {} - for m, v in pairs(value) do - res[m] = v - if res[m].parent ~= nil then - local parentData = getDataValue(storage, res[m].parent) - if parentData ~= nil and parentData[m] ~= nil and parentData[m].token ~= nil then - res[m].token = parentData[m].token - end - res[m].parent = nil - end - end - return res - end - end -end - -function getRandomCount(to) - updateRandomSeed() - return math.random(1, to) -end - -function updateRandomSeed() - local chance = math.random(1,10) - if chance == 1 then - math.randomseed(os.time()) - end -end - +--[[ Lua code. See documentation: http://berserk-games.com/knowledgebase/scripting/ --]] +-- Card size used for autodealing -- + +-- global position constants +ENCOUNTER_DECK_POS = {-3.8, 1, 5.7} +ENCOUNTER_DECK_SPAWN_POS = {-3.8, 3, 5.7} +ENCOUNTER_DECK_DISCARD_POSITION = {-3.8, 0.5, 10.5} +g_cardWith=2.30; +g_cardHeigth=3.40; + +containerId = 'fea079' +tokenDataId = '708279' + + +CACHE = { + object = {}, + data = {} +} + +--[[ The OnLoad function. This is called after everything in the game save finishes loading. +Most of your script code goes here. --]] +function onload() + --Player.White.changeColor('Yellow') + tokenplayerone = { + damageone = "https://i.imgur.com/XIJHw3J.png", + damagethree = "https://i.imgur.com/eqRC712.png", + horrorone = "https://i.imgur.com/Bh0BO47.png", + horrorthree = "https://i.imgur.com/pZvTKA7.png", + resource = "https://i.imgur.com/j5v5E3j.png", + resourcethree = "https://i.imgur.com/1GZsDTt.png", + doom = "https://i.imgur.com/EoL7yaZ.png", + clue = "https://i.imgur.com/wfCaVU0.png" + } + + TOKEN_DATA = { + clue = {image = tokenplayerone.clue, scale = {0.15, 0.15, 0.15}}, + resource = {image = tokenplayerone.resource, scale = {0.17, 0.17, 0.17}}, + doom = {image = tokenplayerone.doom, scale = {0.17, 0.17, 0.17}} + } + + getObjectFromGUID("6161b4").interactable=false + getObjectFromGUID("721ba2").interactable=false + getObjectFromGUID("9f334f").interactable=false + getObjectFromGUID("23a43c").interactable=false + getObjectFromGUID("5450cc").interactable=false + getObjectFromGUID("463022").interactable=false + getObjectFromGUID("9487a4").interactable=false + getObjectFromGUID("91dd9b").interactable=false + getObjectFromGUID("f182ee").interactable=false + +end + +function take_callback(object_spawned, mat) + customObject = object_spawned.getCustomObject() + local player = mat.getGUID(); + + local image = customObject.image + + -- Update global stats + if PULLS[image] == nil then + PULLS[image] = 0 + end + PULLS[image] = PULLS[image] + 1 + -- Update player stats + if PLAYER_PULLS[player][image] == nil then + PLAYER_PULLS[player][image] = 0 + end + PLAYER_PULLS[player][image] = PLAYER_PULLS[player][image] + 1 + +end +MAT_GUID_TO_COLOUR = { + ["8b081b"] = "White", + -- player 2 conrad + ["bd0ff4"] = "Orange", + -- player + ["383d8b"] = "Green", + -- playur 4 olivia + ["0840d5"] = "Red" +} + + +PLAYER_PULLS = { + -- player 1 max + ["8b081b"] = {}, + -- player 2 conrad + ["bd0ff4"] = {}, + -- player + ["383d8b"] = {}, + -- playur 4 olivia + ["0840d5"] = {} +} + +PULLS = { + -- cultist + ["https://i.imgur.com/VzhJJaH.png"] = 0, + -- skull + ["https://i.imgur.com/stbBxtx.png"] = 0, + -- tablet + ["https://i.imgur.com/1plY463.png"] = 0, + -- curse + ["http://cloud-3.steamusercontent.com/ugc/1011565208488654691/8F0B399048EBC34CD24B99AAD415AEC40E679C65/"] = 0, + -- tentacle + ["https://i.imgur.com/lns4fhz.png"] = 0, + -- minus eight + ["https://i.imgur.com/9t3rPTQ.png"] = 0, + -- minus seven + ["https://i.imgur.com/4WRD42n.png"] = 0, + -- minus six + ["https://i.imgur.com/c9qdSzS.png"] = 0, + -- minus five + ["https://i.imgur.com/3Ym1IeG.png"] = 0, + -- minus four + ["https://i.imgur.com/qrgGQRD.png"] = 0, + -- minus three + ["https://i.imgur.com/yfs8gHq.png"] = 0, + -- minus two + ["https://i.imgur.com/bfTg2hb.png"] = 0, + -- minus one + ["https://i.imgur.com/w3XbrCC.png"] = 0, + -- zero + ["https://i.imgur.com/btEtVfd.png"] = 0, + -- plus one + ["https://i.imgur.com/uIx8jbY.png"] = 0, + -- elder thing + ["https://i.imgur.com/ttnspKt.png"] = 0, + -- bless + ["http://cloud-3.steamusercontent.com/ugc/1011565208488650618/B2B081032AF3EFDBD90840A5D6888A3CEA228D66/"] = 0, + -- elder sign + ["https://i.imgur.com/nEmqjmj.png"] = 0, +} + +IMAGE_TOKEN_MAP = { + -- cultist + ["https://i.imgur.com/VzhJJaH.png"] = "cultist", + -- skull + ["https://i.imgur.com/stbBxtx.png"] = "skull", + -- tablet + ["https://i.imgur.com/1plY463.png"] = "tablet", + -- elder thing + ["https://i.imgur.com/ttnspKt.png"] = "Elder Thing", + -- curse + ["http://cloud-3.steamusercontent.com/ugc/1011565208488654691/8F0B399048EBC34CD24B99AAD415AEC40E679C65/"] = "curse", + -- tentacle + ["https://i.imgur.com/lns4fhz.png"] = "Auto-Fail", + -- minus eight + ["https://i.imgur.com/9t3rPTQ.png"] = "-8", + -- minus seven + ["https://i.imgur.com/4WRD42n.png"] = "-7", + -- minus six + ["https://i.imgur.com/c9qdSzS.png"] = "-6", + -- minus five + ["https://i.imgur.com/3Ym1IeG.png"] = "-5", + -- minus four + ["https://i.imgur.com/qrgGQRD.png"] = "-4", + -- minus three + ["https://i.imgur.com/yfs8gHq.png"] = "-3", + -- minus two + ["https://i.imgur.com/bfTg2hb.png"] = "-2", + -- minus one + ["https://i.imgur.com/w3XbrCC.png"] = "-1", + -- zero + ["https://i.imgur.com/btEtVfd.png"] = "0", + -- plus one + ["https://i.imgur.com/uIx8jbY.png"] = "+1", + -- bless + ["http://cloud-3.steamusercontent.com/ugc/1011565208488650618/B2B081032AF3EFDBD90840A5D6888A3CEA228D66/"] = "bless", + -- elder sign + ["https://i.imgur.com/nEmqjmj.png"] = "Elder Sign", +} + +function resetStats() + for key,value in pairs(PULLS) do + PULLS[key] = 0 + end + for playerKey, playerValue in pairs(PLAYER_PULLS) do + for key,value in pairs(PULLS) do + PLAYER_PULLS[playerKey][key] = value + end + end + + +end + +function getPlayerName(playerMatGuid) + local playerColour = MAT_GUID_TO_COLOUR[playerMatGuid] + if Player[playerColour].seated then + return Player[playerColour].steam_name + else + return playerColour + end +end + +function printStats() + local squidKing = "Nobody" + local maxSquid = 0 + + printToAll("\nOverall Game stats\n") + printNonZeroTokenPairs(PULLS) + printToAll("\nIndividual Stats\n") + for playerMatGuid, countTable in pairs(PLAYER_PULLS) do + local playerName = getPlayerName(playerMatGuid) + printToAll(playerName .. " Stats", {r=255,g=0,b=0}) + printNonZeroTokenPairs(PLAYER_PULLS[playerMatGuid]) + playerSquidCount = PLAYER_PULLS[playerMatGuid]["https://i.imgur.com/lns4fhz.png"] + if playerSquidCount != nil and playerSquidCount > maxSquid then + squidKing = playerName + end + end + printToAll(squidKing .. " is an auto-fail magnet.", {r=255,g=0,b=0}) +end + +function printNonZeroTokenPairs(theTable) + for key,value in pairs(theTable) do + if value != 0 then + printToAll(IMAGE_TOKEN_MAP[key] .. '=' .. tostring(value)) + end + end +end + +-- Remove comments to enable autorotate cards on hands. +-- function onObjectEnterScriptingZone(zone, object) +-- Autorotate cards with right side up when entering hand. +-- if zone.getGUID() == "c506bf" or -- white +-- zone.getGUID() == "cbc751" then -- orange +-- object.setRotationSmooth({0,270,0}) +-- elseif zone.getGUID() == "67ce9a" then -- green +-- object.setRotationSmooth({0,0,0}) +-- elseif zone.getGUID() == "57c22c" then -- red +-- object.setRotationSmooth({0,180,0}) +--end +--end + +function findInRadiusBy(pos, radius, filter, debug) + local radius = (radius or 1) + local objList = Physics.cast({ + origin = pos, + direction = {0,1,0}, + type = 2, + size = {radius, radius, radius}, + max_distance = 0, + debug = (debug or false) + }) + + local filteredList = {} + for _, obj in ipairs(objList) do + if filter == nil then + table.insert(filteredList, obj.hit_object) + elseif filter and filter(obj.hit_object) then + table.insert(filteredList, obj.hit_object) + end + end + return filteredList +end + +function dealCardsInRows(paramlist) + local currPosition={}; + local numRow=1; + local numCard=0; + local invMultiplier=1; + local allCardsDealed=0; + if paramlist.inverse then + invMultiplier=-1; + end + if paramlist.maxCardsDealed==nil then + + allCardsDealed=0; + paramlist.maxCardsDealed=paramlist.cardDeck.getQuantity() + + elseif paramlist.maxCardsDealed>=paramlist.cardDeck.getQuantity() or paramlist.maxCardsDealed<=0 then + + allCardsDealed=0; + paramlist.maxCardsDealed=paramlist.cardDeck.getQuantity() + + else + + allCardsDealed=1; + + end + + if paramlist.mode=="x" then + currPosition={paramlist.iniPosition[1]+(2*g_cardWith*invMultiplier*allCardsDealed),paramlist.iniPosition[2],paramlist.iniPosition[3]}; + + else + currPosition={paramlist.iniPosition[1],paramlist.iniPosition[2],paramlist.iniPosition[3]+(2*g_cardWith*invMultiplier*allCardsDealed)}; + + end + + for i = 1,paramlist.maxCardsDealed,1 do + + paramlist.cardDeck.takeObject + ({ + position= currPosition, + smooth= true + }); + + numCard=numCard+1; + if numCard>=paramlist.maxCardRow then + + if paramlist.mode=="x" then + currPosition={paramlist.iniPosition[1]+(2*g_cardWith*invMultiplier*allCardsDealed),paramlist.iniPosition[2],paramlist.iniPosition[3]}; + currPosition[3]=currPosition[3]-(numRow*g_cardHeigth*invMultiplier); + else + currPosition={paramlist.iniPosition[1],paramlist.iniPosition[2],paramlist.iniPosition[3]+(2*g_cardWith*invMultiplier*allCardsDealed)}; + currPosition[1]=currPosition[1]+(numRow*g_cardHeigth*invMultiplier); + end + numCard=0; + numRow=numRow+1; + + else + if paramlist.mode=="x" then + currPosition[1]=currPosition[1]+(g_cardWith*invMultiplier); + else + currPosition[3]=currPosition[3]+(g_cardWith*invMultiplier); + end + end + end +end + +function isDeck(x) + return x.tag == 'Deck' +end + +function isCardOrDeck(x) + return x.tag == 'Card' or isDeck(x) +end + +function drawEncountercard(params) --[[ Parameter Table Position, Table Rotation]] + local position = params[1] + local rotation = params[2] + local isFaceUp = params[3] + local faceUpRotation + if (isFaceUp) then + faceUpRotation = 0 + else + faceUpRotation = 180 + end + local items = findInRadiusBy(ENCOUNTER_DECK_POS, 4, isCardOrDeck) + if #items > 0 then + for i, v in ipairs(items) do + if v.tag == 'Deck' then + v.takeObject({index = 0, position = position, rotation = {0,rotation.y,faceUpRotation}}) + return + end + end +-- we didn't find the deck so just pull the first thing we did find + items[1].setPositionSmooth(position, false, false) + items[1].setRotationSmooth({0,rotation.y,faceUpRotation}, false, false) + return + end +-- nothing here, time to reshuffle + reshuffleEncounterDeck(position, {0,rotation.y,faceUpRotation}) +end + +IS_RESHUFFLING = false +function reshuffleEncounterDeck(position, rotation) + -- finishes moving the deck back and draws a card + local function move(deck) + deck.setPositionSmooth(ENCOUNTER_DECK_SPAWN_POS, true, false) + deck.takeObject({index = 0, position = position, rotation = rotation, flip = false}) + Wait.time(function() IS_RESHUFFLING = false end, 1) + end + -- bail out if we're mid reshuffle + if IS_RESHUFFLING then + return + end + local discarded = findInRadiusBy(ENCOUNTER_DECK_DISCARD_POSITION, 4, isDeck) + if #discarded > 0 then + IS_RESHUFFLING = true + local deck = discarded[1] + if not deck.is_face_down then + deck.flip() + end + deck.shuffle() + Wait.time(|| move(deck), 0.3) + else + printToAll("couldn't find encounter discard pile to reshuffle", {1, 0, 0}) + end +end + +CHAOS_TOKENS = {} +CHAOS_TOKENS_LAST_MAT = nil +function putBackChaosTokens() + local chaosbagposition = chaosbag.getPosition() + for k, token in pairs(CHAOS_TOKENS) do + if token != nil then + chaosbag.putObject(token) + token.setPosition({chaosbagposition[1],chaosbagposition[2]+0.5,chaosbagposition[3]}) + end + end + CHAOS_TOKENS = {} + end + +function drawChaostoken(params) + local mat = params[1] + local tokenOffset = params[2] + local isRightClick = params[3] + local isSameMat = (CHAOS_TOKENS_LAST_MAT == nil or CHAOS_TOKENS_LAST_MAT == mat) + if not isSameMat then + putBackChaosTokens() + end + CHAOS_TOKENS_LAST_MAT = mat + -- if we have left clicked and have no tokens OR if we have right clicked + if isRightClick or #CHAOS_TOKENS == 0 then + local items = getObjectFromGUID("83ef06").getObjects() + for i,v in ipairs(items) do + if items[i].getDescription() == "Chaos Bag" then + chaosbag = getObjectFromGUID(items[i].getGUID()) + break + end + end + -- bail out if we have no tokens + if #chaosbag.getObjects() == 0 then + return + end + chaosbag.shuffle() + -- add the token to the list, compute new position based on list length + tokenOffset[1] = tokenOffset[1] + (0.17 * #CHAOS_TOKENS) + local toPosition = mat.positionToWorld(tokenOffset) + local token = chaosbag.takeObject({ + index = 0, + position = toPosition, + rotation = mat.getRotation(), + callback_function = function(obj) take_callback(obj, mat) end + }) + CHAOS_TOKENS[#CHAOS_TOKENS + 1] = token + return + else + putBackChaosTokens() + end +end + +function spawnToken(params) + -- Position to spawn, + -- rotation vector to apply + -- translation vector to apply + -- token type + local position = params[1] + local tokenType = params[2] + local tokenData = TOKEN_DATA[tokenType] + if tokenData == nil then + error("no token data found for '" .. tokenType .. "'") + end + + local token = spawnObject({ + type = 'Custom_Token', + position = position, + rotation = {x=0, y=270, z=0} + }) + token.setCustomObject({ + image = tokenData['image'], + thickness = 0.3, + merge_distance = 5.0, + stackable = true, + }) + token.use_snap_points=false + token.scale(tokenData['scale']) + return token +end + +function round(params) -- Parameter (int number, int numberDecimalPlaces) + return tonumber(string.format("%." .. (params[2] or 0) .. "f", params[1])) +end + +function roundposition(params) -- Parameter (Table position) + return {round({params[1], 2}),round({params[2], 2}),round({params[3], 2})} +end + +function isEqual(params) --Parameter (Table table1, Table table2) returns true if the tables are equal + if params[1][1] == params[2][1] and params[1][2] == params[2][2] and params[1][3] == params[2][3] then + return true + else + return false + end +end + +function isFaceup(params) --Object object + if params.getRotation()[3] > -5 and params.getRotation()[3] < 5 then + return true + else + return false + end +end + +--Difficulty selector script + +function createSetupButtons(args) + local data = getDataValue('modeData', args.key) + if data ~= nil then + local z = -0.15 + if data.easy ~= nil then + args.object.createButton({ + label = 'Easy', + click_function = 'easyClick', + function_owner = args.object, + position = {0, 0.1, z}, + rotation = {0, 0, 0}, + scale = {0.47, 1, 0.47}, + height = 200, + width = 1150, + font_size = 100, + color = {0.87, 0.8, 0.70}, + font_color = {0, 0, 0} + }) + z = z + 0.20 + end + if data.normal ~= nil then + args.object.createButton({ + label = 'Standard', + click_function = 'normalClick', + function_owner = args.object, + position = {0, 0.1, z}, + rotation = {0, 0, 0}, + scale = {0.47, 1, 0.47}, + height = 200, + width = 1150, + font_size = 100, + color = {0.87, 0.8, 0.70}, + font_color = {0, 0, 0} + }) + z = z + 0.20 + end + if data.hard ~= nil then + args.object.createButton({ + label = 'Hard', + click_function = 'hardClick', + function_owner = args.object, + position = {0, 0.1, z}, + rotation = {0, 0, 0}, + scale = {0.47, 1, 0.47}, + height = 200, + width = 1150, + font_size = 100, + color = {0.87, 0.8, 0.70}, + font_color = {0, 0, 0} + }) + z = z + 0.20 + end + if data.expert ~= nil then + args.object.createButton({ + label = 'Expert', + click_function = 'expertClick', + function_owner = args.object, + position = {0, 0.1, z}, + rotation = {0, 0, 0}, + scale = {0.47, 1, 0.47}, + height = 200, + width = 1150, + font_size = 100, + color = {0.87, 0.8, 0.70}, + font_color = {0, 0, 0} + }) + z = z + 0.20 + end + z = z + 0.10 + if data.standalone ~= nil then + args.object.createButton({ + label = 'Standalone', + click_function = 'standaloneClick', + function_owner = args.object, + position = {0, 0.1, z}, + rotation = {0, 0, 0}, + scale = {0.47, 1, 0.47}, + height = 200, + width = 1150, + font_size = 100, + color = {0.87, 0.8, 0.70}, + font_color = {0, 0, 0} + }) + end + end +end + +function fillContainer(args) + local container = getObjectCache(containerId) + + if container ~= nil then + local data = getDataValue('modeData', args.key) + if data == nil then return end + + local value = data[args.mode] + if value == nil or value.token == nil then return end + + local pos = container.getPosition() + if args.object ~= nil then + pos = args.object.getPosition() + end + + cleanContainer(container) + + for _, token in ipairs(value.token) do + local obj = spawnToken_2(token, pos) + if obj ~= nil then + container.putObject(obj) + end + end + + if value.append ~= nil then + for _, token in ipairs(value.append) do + local obj = spawnToken_2(token, pos) + if obj ~= nil then + container.putObject(obj) + end + end + end + + if value.random then + local n = #value.random + if n > 0 then + for _, token in ipairs(value.random[getRandomCount(n)]) do + local obj = spawnToken_2(token, pos) + if obj ~= nil then + container.putObject(obj) + end + end + end + end + + if value.message then + broadcastToAll(value.message) + end + if value.warning then + broadcastToAll(value.warning, { 1, 0.5, 0.5 }) + end + end +end + +function spawnToken_2(id, pos) + local url = getImageUrl(id) + if url ~= '' then + local obj = spawnObject({ + type = 'Custom_Tile', + position = {pos.x, pos.y + 3, pos.z}, + rotation = {x = 0, y = 260, z = 0} + }) + obj.setCustomObject({ + type = 2, + image = url, + thickness = 0.10, + }) + obj.scale {0.81, 1, 0.81} + return obj + end +end + +function getImageUrl(id) + if id == 'p1' then return 'https://i.imgur.com/uIx8jbY.png' end + if id == '0' then return 'https://i.imgur.com/btEtVfd.png' end + if id == 'm1' then return 'https://i.imgur.com/w3XbrCC.png' end + if id == 'm2' then return 'https://i.imgur.com/bfTg2hb.png' end + if id == 'm3' then return 'https://i.imgur.com/yfs8gHq.png' end + if id == 'm4' then return 'https://i.imgur.com/qrgGQRD.png' end + if id == 'm5' then return 'https://i.imgur.com/3Ym1IeG.png' end + if id == 'm6' then return 'https://i.imgur.com/c9qdSzS.png' end + if id == 'm7' then return 'https://i.imgur.com/4WRD42n.png' end + if id == 'm8' then return 'https://i.imgur.com/9t3rPTQ.png' end + if id == 'skull' then return 'https://i.imgur.com/stbBxtx.png' end + if id == 'cultist' then return 'https://i.imgur.com/VzhJJaH.png' end + if id == 'tablet' then return 'https://i.imgur.com/1plY463.png' end + if id == 'elder' then return 'https://i.imgur.com/ttnspKt.png' end + if id == 'red' then return 'https://i.imgur.com/lns4fhz.png' end + if id == 'blue' then return 'https://i.imgur.com/nEmqjmj.png' end + return '' +end + +function cleanContainer(container) + for _, item in ipairs(container.getObjects()) do + destroyObject(container.takeObject({})) + end +end + +function getObjectsInZone(zoneId) + local zoneObject = getObjectCache(zoneId) + + if zoneObject == nil then + return + end + + local objectsInZone = zoneObject.getObjects() + local objectsFound = {} + + for i = 1, #objectsInZone do + local object = objectsInZone[i] + if object.tag == 'Bag' then + table.insert(objectsFound, object.guid) + end + end + + if #objectsFound > 0 then + return objectsFound + end +end + +function getObjectCache(id) + if CACHE.object[id] == nil then + CACHE.object[id] = getObjectFromGUID(id) + end + return CACHE.object[id] +end + +function getDataTable(storage) + if CACHE.data[storage] == nil then + local obj = getObjectCache(tokenDataId) + if obj ~= nil then + CACHE.data[storage] = obj.getTable(storage) + end + end + return CACHE.data[storage] +end + +function getDataValue(storage, key) + local data = getDataTable(storage) + if data ~= nil then + local value = data[key] + if value ~= nil then + local res = {} + for m, v in pairs(value) do + res[m] = v + if res[m].parent ~= nil then + local parentData = getDataValue(storage, res[m].parent) + if parentData ~= nil and parentData[m] ~= nil and parentData[m].token ~= nil then + res[m].token = parentData[m].token + end + res[m].parent = nil + end + end + return res + end + end +end + +function getRandomCount(to) + updateRandomSeed() + return math.random(1, to) +end + +function updateRandomSeed() + local chance = math.random(1,10) + if chance == 1 then + math.randomseed(os.time()) + end +end + diff --git a/unpacked/Custom_Model 032300.ttslua b/unpacked/Custom_Model 032300.ttslua index 3308d2100..e92143ce9 100644 --- a/unpacked/Custom_Model 032300.ttslua +++ b/unpacked/Custom_Model 032300.ttslua @@ -1,113 +1,113 @@ ---Counting Bowl by MrStump - ---Table of items which can be counted in this Bowl ---Each entry has 2 things to enter - --a name (what is in the name field of that object) - --a value (how much it is worth) ---A number in the items description will override the number entry in this table -validCountItemList = { - ["Clue"] = 1, - [""] = 1, - --["Name3"] = 2, - --["Name4"] = 31, - --Add more entries as needed - --Remove the -- from before a line for the script to use it -} - ---END OF CODE TO EDIT - -function onLoad() - timerID = self.getGUID()..math.random(9999999999999) - --Sets position/color for the button, spawns it - self.createButton({ - label="", click_function="removeAllClues", function_owner=self, - position={0,0,0}, rotation={0,8,0}, height=0, width=0, - font_color={0,0,0}, font_size=2000 - }) - --Start timer which repeats forever, running countItems() every second - Timer.create({ - identifier=timerID, - function_name="countItems", function_owner=self, - repetitions=0, delay=1 - }) - exposedValue = 0 - trashCan = getObjectFromGUID("147e80") -end - -function findValidItemsInSphere() - return filterByValidity(findItemsInSphere()) -end - ---Activated once per second, counts items in bowls -function countItems() - local totalValue = -1 - local countableItems = findValidItemsInSphere() - for ind, entry in ipairs(countableItems) do - local descValue = tonumber(entry.hit_object.getDescription()) - local stackMult = math.abs(entry.hit_object.getQuantity()) - --Use value in description if available - if descValue ~= nil then - totalValue = totalValue + descValue * stackMult - else - --Otherwise use the value in validCountItemList - totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult - end - end - exposedValue = totalValue - --Updates the number display - self.editButton({index=0, label=totalValue}) -end - -function filterByValidity(items) - retval = {} - for _, entry in ipairs(items) do - --Ignore the bowl - if entry.hit_object ~= self then - --Ignore if not in validCountItemList - local tableEntry = validCountItemList[entry.hit_object.getName()] - if tableEntry ~= nil then - table.insert(retval, entry) - end - end - end - return retval -end - - ---Gets the items in the bowl for countItems to count -function findItemsInSphere() - --Find scaling factor - local scale = self.getScale() - --Set position for the sphere - local pos = self.getPosition() - pos.y=pos.y+(1.25*scale.y) - --Ray trace to get all objects - return Physics.cast({ - origin=pos, direction={0,1,0}, type=2, max_distance=0, - size={6*scale.x,6*scale.y,6*scale.z}, --debug=true - }) -end - -function removeAllClues() - startLuaCoroutine(self, "clueRemovalCoroutine") -end - -function clueRemovalCoroutine() - for _, entry in ipairs(findValidItemsInSphere()) do - -- Do not put the table in the garbage - if entry.hit_object.getGUID() ~= "4ee1f2" then - --delay for animation purposes - for k=1,10 do - coroutine.yield(0) - end - trashCan.putObject(entry.hit_object) - end - end - --coroutines must return a value - return 1 -end - - -function onDestroy() - Timer.destroy(timerID) +--Counting Bowl by MrStump + +--Table of items which can be counted in this Bowl +--Each entry has 2 things to enter + --a name (what is in the name field of that object) + --a value (how much it is worth) +--A number in the items description will override the number entry in this table +validCountItemList = { + ["Clue"] = 1, + [""] = 1, + --["Name3"] = 2, + --["Name4"] = 31, + --Add more entries as needed + --Remove the -- from before a line for the script to use it +} + +--END OF CODE TO EDIT + +function onLoad() + timerID = self.getGUID()..math.random(9999999999999) + --Sets position/color for the button, spawns it + self.createButton({ + label="", click_function="removeAllClues", function_owner=self, + position={0,0,0}, rotation={0,8,0}, height=0, width=0, + font_color={0,0,0}, font_size=2000 + }) + --Start timer which repeats forever, running countItems() every second + Timer.create({ + identifier=timerID, + function_name="countItems", function_owner=self, + repetitions=0, delay=1 + }) + exposedValue = 0 + trashCan = getObjectFromGUID("147e80") +end + +function findValidItemsInSphere() + return filterByValidity(findItemsInSphere()) +end + +--Activated once per second, counts items in bowls +function countItems() + local totalValue = -1 + local countableItems = findValidItemsInSphere() + for ind, entry in ipairs(countableItems) do + local descValue = tonumber(entry.hit_object.getDescription()) + local stackMult = math.abs(entry.hit_object.getQuantity()) + --Use value in description if available + if descValue ~= nil then + totalValue = totalValue + descValue * stackMult + else + --Otherwise use the value in validCountItemList + totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult + end + end + exposedValue = totalValue + --Updates the number display + self.editButton({index=0, label=totalValue}) +end + +function filterByValidity(items) + retval = {} + for _, entry in ipairs(items) do + --Ignore the bowl + if entry.hit_object ~= self then + --Ignore if not in validCountItemList + local tableEntry = validCountItemList[entry.hit_object.getName()] + if tableEntry ~= nil then + table.insert(retval, entry) + end + end + end + return retval +end + + +--Gets the items in the bowl for countItems to count +function findItemsInSphere() + --Find scaling factor + local scale = self.getScale() + --Set position for the sphere + local pos = self.getPosition() + pos.y=pos.y+(1.25*scale.y) + --Ray trace to get all objects + return Physics.cast({ + origin=pos, direction={0,1,0}, type=2, max_distance=0, + size={6*scale.x,6*scale.y,6*scale.z}, --debug=true + }) +end + +function removeAllClues() + startLuaCoroutine(self, "clueRemovalCoroutine") +end + +function clueRemovalCoroutine() + for _, entry in ipairs(findValidItemsInSphere()) do + -- Do not put the table in the garbage + if entry.hit_object.getGUID() ~= "4ee1f2" then + --delay for animation purposes + for k=1,10 do + coroutine.yield(0) + end + trashCan.putObject(entry.hit_object) + end + end + --coroutines must return a value + return 1 +end + + +function onDestroy() + Timer.destroy(timerID) end \ No newline at end of file diff --git a/unpacked/Custom_Model 1769ed.ttslua b/unpacked/Custom_Model 1769ed.ttslua index 3308d2100..e92143ce9 100644 --- a/unpacked/Custom_Model 1769ed.ttslua +++ b/unpacked/Custom_Model 1769ed.ttslua @@ -1,113 +1,113 @@ ---Counting Bowl by MrStump - ---Table of items which can be counted in this Bowl ---Each entry has 2 things to enter - --a name (what is in the name field of that object) - --a value (how much it is worth) ---A number in the items description will override the number entry in this table -validCountItemList = { - ["Clue"] = 1, - [""] = 1, - --["Name3"] = 2, - --["Name4"] = 31, - --Add more entries as needed - --Remove the -- from before a line for the script to use it -} - ---END OF CODE TO EDIT - -function onLoad() - timerID = self.getGUID()..math.random(9999999999999) - --Sets position/color for the button, spawns it - self.createButton({ - label="", click_function="removeAllClues", function_owner=self, - position={0,0,0}, rotation={0,8,0}, height=0, width=0, - font_color={0,0,0}, font_size=2000 - }) - --Start timer which repeats forever, running countItems() every second - Timer.create({ - identifier=timerID, - function_name="countItems", function_owner=self, - repetitions=0, delay=1 - }) - exposedValue = 0 - trashCan = getObjectFromGUID("147e80") -end - -function findValidItemsInSphere() - return filterByValidity(findItemsInSphere()) -end - ---Activated once per second, counts items in bowls -function countItems() - local totalValue = -1 - local countableItems = findValidItemsInSphere() - for ind, entry in ipairs(countableItems) do - local descValue = tonumber(entry.hit_object.getDescription()) - local stackMult = math.abs(entry.hit_object.getQuantity()) - --Use value in description if available - if descValue ~= nil then - totalValue = totalValue + descValue * stackMult - else - --Otherwise use the value in validCountItemList - totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult - end - end - exposedValue = totalValue - --Updates the number display - self.editButton({index=0, label=totalValue}) -end - -function filterByValidity(items) - retval = {} - for _, entry in ipairs(items) do - --Ignore the bowl - if entry.hit_object ~= self then - --Ignore if not in validCountItemList - local tableEntry = validCountItemList[entry.hit_object.getName()] - if tableEntry ~= nil then - table.insert(retval, entry) - end - end - end - return retval -end - - ---Gets the items in the bowl for countItems to count -function findItemsInSphere() - --Find scaling factor - local scale = self.getScale() - --Set position for the sphere - local pos = self.getPosition() - pos.y=pos.y+(1.25*scale.y) - --Ray trace to get all objects - return Physics.cast({ - origin=pos, direction={0,1,0}, type=2, max_distance=0, - size={6*scale.x,6*scale.y,6*scale.z}, --debug=true - }) -end - -function removeAllClues() - startLuaCoroutine(self, "clueRemovalCoroutine") -end - -function clueRemovalCoroutine() - for _, entry in ipairs(findValidItemsInSphere()) do - -- Do not put the table in the garbage - if entry.hit_object.getGUID() ~= "4ee1f2" then - --delay for animation purposes - for k=1,10 do - coroutine.yield(0) - end - trashCan.putObject(entry.hit_object) - end - end - --coroutines must return a value - return 1 -end - - -function onDestroy() - Timer.destroy(timerID) +--Counting Bowl by MrStump + +--Table of items which can be counted in this Bowl +--Each entry has 2 things to enter + --a name (what is in the name field of that object) + --a value (how much it is worth) +--A number in the items description will override the number entry in this table +validCountItemList = { + ["Clue"] = 1, + [""] = 1, + --["Name3"] = 2, + --["Name4"] = 31, + --Add more entries as needed + --Remove the -- from before a line for the script to use it +} + +--END OF CODE TO EDIT + +function onLoad() + timerID = self.getGUID()..math.random(9999999999999) + --Sets position/color for the button, spawns it + self.createButton({ + label="", click_function="removeAllClues", function_owner=self, + position={0,0,0}, rotation={0,8,0}, height=0, width=0, + font_color={0,0,0}, font_size=2000 + }) + --Start timer which repeats forever, running countItems() every second + Timer.create({ + identifier=timerID, + function_name="countItems", function_owner=self, + repetitions=0, delay=1 + }) + exposedValue = 0 + trashCan = getObjectFromGUID("147e80") +end + +function findValidItemsInSphere() + return filterByValidity(findItemsInSphere()) +end + +--Activated once per second, counts items in bowls +function countItems() + local totalValue = -1 + local countableItems = findValidItemsInSphere() + for ind, entry in ipairs(countableItems) do + local descValue = tonumber(entry.hit_object.getDescription()) + local stackMult = math.abs(entry.hit_object.getQuantity()) + --Use value in description if available + if descValue ~= nil then + totalValue = totalValue + descValue * stackMult + else + --Otherwise use the value in validCountItemList + totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult + end + end + exposedValue = totalValue + --Updates the number display + self.editButton({index=0, label=totalValue}) +end + +function filterByValidity(items) + retval = {} + for _, entry in ipairs(items) do + --Ignore the bowl + if entry.hit_object ~= self then + --Ignore if not in validCountItemList + local tableEntry = validCountItemList[entry.hit_object.getName()] + if tableEntry ~= nil then + table.insert(retval, entry) + end + end + end + return retval +end + + +--Gets the items in the bowl for countItems to count +function findItemsInSphere() + --Find scaling factor + local scale = self.getScale() + --Set position for the sphere + local pos = self.getPosition() + pos.y=pos.y+(1.25*scale.y) + --Ray trace to get all objects + return Physics.cast({ + origin=pos, direction={0,1,0}, type=2, max_distance=0, + size={6*scale.x,6*scale.y,6*scale.z}, --debug=true + }) +end + +function removeAllClues() + startLuaCoroutine(self, "clueRemovalCoroutine") +end + +function clueRemovalCoroutine() + for _, entry in ipairs(findValidItemsInSphere()) do + -- Do not put the table in the garbage + if entry.hit_object.getGUID() ~= "4ee1f2" then + --delay for animation purposes + for k=1,10 do + coroutine.yield(0) + end + trashCan.putObject(entry.hit_object) + end + end + --coroutines must return a value + return 1 +end + + +function onDestroy() + Timer.destroy(timerID) end \ No newline at end of file diff --git a/unpacked/Custom_Model 37be78.ttslua b/unpacked/Custom_Model 37be78.ttslua index 3308d2100..e92143ce9 100644 --- a/unpacked/Custom_Model 37be78.ttslua +++ b/unpacked/Custom_Model 37be78.ttslua @@ -1,113 +1,113 @@ ---Counting Bowl by MrStump - ---Table of items which can be counted in this Bowl ---Each entry has 2 things to enter - --a name (what is in the name field of that object) - --a value (how much it is worth) ---A number in the items description will override the number entry in this table -validCountItemList = { - ["Clue"] = 1, - [""] = 1, - --["Name3"] = 2, - --["Name4"] = 31, - --Add more entries as needed - --Remove the -- from before a line for the script to use it -} - ---END OF CODE TO EDIT - -function onLoad() - timerID = self.getGUID()..math.random(9999999999999) - --Sets position/color for the button, spawns it - self.createButton({ - label="", click_function="removeAllClues", function_owner=self, - position={0,0,0}, rotation={0,8,0}, height=0, width=0, - font_color={0,0,0}, font_size=2000 - }) - --Start timer which repeats forever, running countItems() every second - Timer.create({ - identifier=timerID, - function_name="countItems", function_owner=self, - repetitions=0, delay=1 - }) - exposedValue = 0 - trashCan = getObjectFromGUID("147e80") -end - -function findValidItemsInSphere() - return filterByValidity(findItemsInSphere()) -end - ---Activated once per second, counts items in bowls -function countItems() - local totalValue = -1 - local countableItems = findValidItemsInSphere() - for ind, entry in ipairs(countableItems) do - local descValue = tonumber(entry.hit_object.getDescription()) - local stackMult = math.abs(entry.hit_object.getQuantity()) - --Use value in description if available - if descValue ~= nil then - totalValue = totalValue + descValue * stackMult - else - --Otherwise use the value in validCountItemList - totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult - end - end - exposedValue = totalValue - --Updates the number display - self.editButton({index=0, label=totalValue}) -end - -function filterByValidity(items) - retval = {} - for _, entry in ipairs(items) do - --Ignore the bowl - if entry.hit_object ~= self then - --Ignore if not in validCountItemList - local tableEntry = validCountItemList[entry.hit_object.getName()] - if tableEntry ~= nil then - table.insert(retval, entry) - end - end - end - return retval -end - - ---Gets the items in the bowl for countItems to count -function findItemsInSphere() - --Find scaling factor - local scale = self.getScale() - --Set position for the sphere - local pos = self.getPosition() - pos.y=pos.y+(1.25*scale.y) - --Ray trace to get all objects - return Physics.cast({ - origin=pos, direction={0,1,0}, type=2, max_distance=0, - size={6*scale.x,6*scale.y,6*scale.z}, --debug=true - }) -end - -function removeAllClues() - startLuaCoroutine(self, "clueRemovalCoroutine") -end - -function clueRemovalCoroutine() - for _, entry in ipairs(findValidItemsInSphere()) do - -- Do not put the table in the garbage - if entry.hit_object.getGUID() ~= "4ee1f2" then - --delay for animation purposes - for k=1,10 do - coroutine.yield(0) - end - trashCan.putObject(entry.hit_object) - end - end - --coroutines must return a value - return 1 -end - - -function onDestroy() - Timer.destroy(timerID) +--Counting Bowl by MrStump + +--Table of items which can be counted in this Bowl +--Each entry has 2 things to enter + --a name (what is in the name field of that object) + --a value (how much it is worth) +--A number in the items description will override the number entry in this table +validCountItemList = { + ["Clue"] = 1, + [""] = 1, + --["Name3"] = 2, + --["Name4"] = 31, + --Add more entries as needed + --Remove the -- from before a line for the script to use it +} + +--END OF CODE TO EDIT + +function onLoad() + timerID = self.getGUID()..math.random(9999999999999) + --Sets position/color for the button, spawns it + self.createButton({ + label="", click_function="removeAllClues", function_owner=self, + position={0,0,0}, rotation={0,8,0}, height=0, width=0, + font_color={0,0,0}, font_size=2000 + }) + --Start timer which repeats forever, running countItems() every second + Timer.create({ + identifier=timerID, + function_name="countItems", function_owner=self, + repetitions=0, delay=1 + }) + exposedValue = 0 + trashCan = getObjectFromGUID("147e80") +end + +function findValidItemsInSphere() + return filterByValidity(findItemsInSphere()) +end + +--Activated once per second, counts items in bowls +function countItems() + local totalValue = -1 + local countableItems = findValidItemsInSphere() + for ind, entry in ipairs(countableItems) do + local descValue = tonumber(entry.hit_object.getDescription()) + local stackMult = math.abs(entry.hit_object.getQuantity()) + --Use value in description if available + if descValue ~= nil then + totalValue = totalValue + descValue * stackMult + else + --Otherwise use the value in validCountItemList + totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult + end + end + exposedValue = totalValue + --Updates the number display + self.editButton({index=0, label=totalValue}) +end + +function filterByValidity(items) + retval = {} + for _, entry in ipairs(items) do + --Ignore the bowl + if entry.hit_object ~= self then + --Ignore if not in validCountItemList + local tableEntry = validCountItemList[entry.hit_object.getName()] + if tableEntry ~= nil then + table.insert(retval, entry) + end + end + end + return retval +end + + +--Gets the items in the bowl for countItems to count +function findItemsInSphere() + --Find scaling factor + local scale = self.getScale() + --Set position for the sphere + local pos = self.getPosition() + pos.y=pos.y+(1.25*scale.y) + --Ray trace to get all objects + return Physics.cast({ + origin=pos, direction={0,1,0}, type=2, max_distance=0, + size={6*scale.x,6*scale.y,6*scale.z}, --debug=true + }) +end + +function removeAllClues() + startLuaCoroutine(self, "clueRemovalCoroutine") +end + +function clueRemovalCoroutine() + for _, entry in ipairs(findValidItemsInSphere()) do + -- Do not put the table in the garbage + if entry.hit_object.getGUID() ~= "4ee1f2" then + --delay for animation purposes + for k=1,10 do + coroutine.yield(0) + end + trashCan.putObject(entry.hit_object) + end + end + --coroutines must return a value + return 1 +end + + +function onDestroy() + Timer.destroy(timerID) end \ No newline at end of file diff --git a/unpacked/Custom_Model d86b7c.ttslua b/unpacked/Custom_Model d86b7c.ttslua index 3308d2100..e92143ce9 100644 --- a/unpacked/Custom_Model d86b7c.ttslua +++ b/unpacked/Custom_Model d86b7c.ttslua @@ -1,113 +1,113 @@ ---Counting Bowl by MrStump - ---Table of items which can be counted in this Bowl ---Each entry has 2 things to enter - --a name (what is in the name field of that object) - --a value (how much it is worth) ---A number in the items description will override the number entry in this table -validCountItemList = { - ["Clue"] = 1, - [""] = 1, - --["Name3"] = 2, - --["Name4"] = 31, - --Add more entries as needed - --Remove the -- from before a line for the script to use it -} - ---END OF CODE TO EDIT - -function onLoad() - timerID = self.getGUID()..math.random(9999999999999) - --Sets position/color for the button, spawns it - self.createButton({ - label="", click_function="removeAllClues", function_owner=self, - position={0,0,0}, rotation={0,8,0}, height=0, width=0, - font_color={0,0,0}, font_size=2000 - }) - --Start timer which repeats forever, running countItems() every second - Timer.create({ - identifier=timerID, - function_name="countItems", function_owner=self, - repetitions=0, delay=1 - }) - exposedValue = 0 - trashCan = getObjectFromGUID("147e80") -end - -function findValidItemsInSphere() - return filterByValidity(findItemsInSphere()) -end - ---Activated once per second, counts items in bowls -function countItems() - local totalValue = -1 - local countableItems = findValidItemsInSphere() - for ind, entry in ipairs(countableItems) do - local descValue = tonumber(entry.hit_object.getDescription()) - local stackMult = math.abs(entry.hit_object.getQuantity()) - --Use value in description if available - if descValue ~= nil then - totalValue = totalValue + descValue * stackMult - else - --Otherwise use the value in validCountItemList - totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult - end - end - exposedValue = totalValue - --Updates the number display - self.editButton({index=0, label=totalValue}) -end - -function filterByValidity(items) - retval = {} - for _, entry in ipairs(items) do - --Ignore the bowl - if entry.hit_object ~= self then - --Ignore if not in validCountItemList - local tableEntry = validCountItemList[entry.hit_object.getName()] - if tableEntry ~= nil then - table.insert(retval, entry) - end - end - end - return retval -end - - ---Gets the items in the bowl for countItems to count -function findItemsInSphere() - --Find scaling factor - local scale = self.getScale() - --Set position for the sphere - local pos = self.getPosition() - pos.y=pos.y+(1.25*scale.y) - --Ray trace to get all objects - return Physics.cast({ - origin=pos, direction={0,1,0}, type=2, max_distance=0, - size={6*scale.x,6*scale.y,6*scale.z}, --debug=true - }) -end - -function removeAllClues() - startLuaCoroutine(self, "clueRemovalCoroutine") -end - -function clueRemovalCoroutine() - for _, entry in ipairs(findValidItemsInSphere()) do - -- Do not put the table in the garbage - if entry.hit_object.getGUID() ~= "4ee1f2" then - --delay for animation purposes - for k=1,10 do - coroutine.yield(0) - end - trashCan.putObject(entry.hit_object) - end - end - --coroutines must return a value - return 1 -end - - -function onDestroy() - Timer.destroy(timerID) +--Counting Bowl by MrStump + +--Table of items which can be counted in this Bowl +--Each entry has 2 things to enter + --a name (what is in the name field of that object) + --a value (how much it is worth) +--A number in the items description will override the number entry in this table +validCountItemList = { + ["Clue"] = 1, + [""] = 1, + --["Name3"] = 2, + --["Name4"] = 31, + --Add more entries as needed + --Remove the -- from before a line for the script to use it +} + +--END OF CODE TO EDIT + +function onLoad() + timerID = self.getGUID()..math.random(9999999999999) + --Sets position/color for the button, spawns it + self.createButton({ + label="", click_function="removeAllClues", function_owner=self, + position={0,0,0}, rotation={0,8,0}, height=0, width=0, + font_color={0,0,0}, font_size=2000 + }) + --Start timer which repeats forever, running countItems() every second + Timer.create({ + identifier=timerID, + function_name="countItems", function_owner=self, + repetitions=0, delay=1 + }) + exposedValue = 0 + trashCan = getObjectFromGUID("147e80") +end + +function findValidItemsInSphere() + return filterByValidity(findItemsInSphere()) +end + +--Activated once per second, counts items in bowls +function countItems() + local totalValue = -1 + local countableItems = findValidItemsInSphere() + for ind, entry in ipairs(countableItems) do + local descValue = tonumber(entry.hit_object.getDescription()) + local stackMult = math.abs(entry.hit_object.getQuantity()) + --Use value in description if available + if descValue ~= nil then + totalValue = totalValue + descValue * stackMult + else + --Otherwise use the value in validCountItemList + totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult + end + end + exposedValue = totalValue + --Updates the number display + self.editButton({index=0, label=totalValue}) +end + +function filterByValidity(items) + retval = {} + for _, entry in ipairs(items) do + --Ignore the bowl + if entry.hit_object ~= self then + --Ignore if not in validCountItemList + local tableEntry = validCountItemList[entry.hit_object.getName()] + if tableEntry ~= nil then + table.insert(retval, entry) + end + end + end + return retval +end + + +--Gets the items in the bowl for countItems to count +function findItemsInSphere() + --Find scaling factor + local scale = self.getScale() + --Set position for the sphere + local pos = self.getPosition() + pos.y=pos.y+(1.25*scale.y) + --Ray trace to get all objects + return Physics.cast({ + origin=pos, direction={0,1,0}, type=2, max_distance=0, + size={6*scale.x,6*scale.y,6*scale.z}, --debug=true + }) +end + +function removeAllClues() + startLuaCoroutine(self, "clueRemovalCoroutine") +end + +function clueRemovalCoroutine() + for _, entry in ipairs(findValidItemsInSphere()) do + -- Do not put the table in the garbage + if entry.hit_object.getGUID() ~= "4ee1f2" then + --delay for animation purposes + for k=1,10 do + coroutine.yield(0) + end + trashCan.putObject(entry.hit_object) + end + end + --coroutines must return a value + return 1 +end + + +function onDestroy() + Timer.destroy(timerID) end \ No newline at end of file diff --git a/unpacked/Custom_Model Custom Data Helper c0b834.ttslua b/unpacked/Custom_Model Custom Data Helper c0b834.ttslua index fa8727391..3dbaffb65 100644 --- a/unpacked/Custom_Model Custom Data Helper c0b834.ttslua +++ b/unpacked/Custom_Model Custom Data Helper c0b834.ttslua @@ -1,37 +1,37 @@ --- set true to enable debug logging -DEBUG = false - -function log(message) - if DEBUG then - print(message) - end -end - ---[[ -Known locations and clues. We check this to determine if we should -atttempt to spawn clues, first we look for _ and if -we find nothing we look for -format is [location_guid -> clueCount] -]] -LOCATIONS_DATA_JSON = [[ -{ - "San Francisco": {"type": "fixed", "value": 1, "clueSide": "back"}, - " Arkham": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Buenos Aires": {"type": "fixed", "value": 2, "clueSide": "back"}, - " London": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Rome": {"type": "perPlayer", "value": 3, "clueSide": "front"}, - "Istanbul": {"type": "perPlayer", "value": 4, "clueSide": "front"}, - "Tokyo_123abc": {"type": "perPlayer", "value": 0, "clueSide": "back"}, +-- set true to enable debug logging +DEBUG = false + +function log(message) + if DEBUG then + print(message) + end +end + +--[[ +Known locations and clues. We check this to determine if we should +atttempt to spawn clues, first we look for _ and if +we find nothing we look for +format is [location_guid -> clueCount] +]] +LOCATIONS_DATA_JSON = [[ +{ + "San Francisco": {"type": "fixed", "value": 1, "clueSide": "back"}, + " Arkham": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Buenos Aires": {"type": "fixed", "value": 2, "clueSide": "back"}, + " London": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Rome": {"type": "perPlayer", "value": 3, "clueSide": "front"}, + "Istanbul": {"type": "perPlayer", "value": 4, "clueSide": "front"}, + "Tokyo_123abc": {"type": "perPlayer", "value": 0, "clueSide": "back"}, "Tokyo_456efg": {"type": "perPlayer", "value": 4, "clueSide": "back"}, "Tokyo": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Shanghai_123": {"type": "fixed", "value": 12, "clueSide": "front"}, - "Sydney": {"type": "fixed", "value": 0, "clueSide": "front"} -} -]] - -LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) - -function onload(save_state) - local playArea = getObjectFromGUID('721ba2') - playArea.call("updateLocations", {self.getGUID()}) -end + "Shanghai_123": {"type": "fixed", "value": 12, "clueSide": "front"}, + "Sydney": {"type": "fixed", "value": 0, "clueSide": "front"} +} +]] + +LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) + +function onload(save_state) + local playArea = getObjectFromGUID('721ba2') + playArea.call("updateLocations", {self.getGUID()}) +end diff --git a/unpacked/Custom_Model_Bag Arkhamdb bag b85d6d.ttslua b/unpacked/Custom_Model_Bag Arkhamdb bag b85d6d.ttslua index bd80beb3c..edbcb88e7 100644 --- a/unpacked/Custom_Model_Bag Arkhamdb bag b85d6d.ttslua +++ b/unpacked/Custom_Model_Bag Arkhamdb bag b85d6d.ttslua @@ -1,36 +1,36 @@ -function onLoad() - - - - - ---self.interactable = false -self.createButton({ - click_function= "onButtonClick", - function_owner= self, - position= {0, 1.84, 0}, - width = 1500, - height = 1000, - color = {0,0,0,0}, - tooltip= "click here to load cards first", -})end - -function onButtonClick(obj, playerColor) -if Player[playerColor].admin and self.getQuantity() > 0 then - - - - --AllCard Deck - self.takeObject ({ - position= {-63.36, 5, -65.69}, - rotation = {180,90,0}, - smooth= true,}) - - --AllCard Deck - self.takeObject ({ - position= {-63.34, 1.43, -77.75}, - rotation = {180,90,0}, - smooth= true,}) - -end +function onLoad() + + + + + +--self.interactable = false +self.createButton({ + click_function= "onButtonClick", + function_owner= self, + position= {0, 1.84, 0}, + width = 1500, + height = 1000, + color = {0,0,0,0}, + tooltip= "click here to load cards first", +})end + +function onButtonClick(obj, playerColor) +if Player[playerColor].admin and self.getQuantity() > 0 then + + + + --AllCard Deck + self.takeObject ({ + position= {-63.36, 5, -65.69}, + rotation = {180,90,0}, + smooth= true,}) + + --AllCard Deck + self.takeObject ({ + position= {-63.34, 1.43, -77.75}, + rotation = {180,90,0}, + smooth= true,}) + +end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Chaos Bag fea079.ttslua b/unpacked/Custom_Model_Bag Chaos Bag fea079.ttslua index 3d2f7ab59..eba7fa0dc 100644 --- a/unpacked/Custom_Model_Bag Chaos Bag fea079.ttslua +++ b/unpacked/Custom_Model_Bag Chaos Bag fea079.ttslua @@ -1,5 +1,5 @@ -function onCollisionEnter(collision_info) - self.shuffle() - self.shuffle() - self.shuffle() +function onCollisionEnter(collision_info) + self.shuffle() + self.shuffle() + self.shuffle() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6.ttslua b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6.ttslua index a1bbfd97e..e8a8f39de 100644 --- a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6.ttslua +++ b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,5,-2}, rotation={0,0,0}, height=250, width=600, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * 4 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={1.5,5,2}, rotation={0,0,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.2,5,2}, rotation={0,0,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-3.5,5,2}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Clicker", click_function="buttonClick_place", function_owner=self, - position={4.2,1,0}, rotation={0,0,0}, height=500, width=1100, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Counter", click_function="buttonClick_recall", function_owner=self, - position={-4.2,1,-0.1}, rotation={0,0,0}, height=500, width=1300, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-6,1,0}, rotation={0,90,0}, height=500, width=1200, --- font_size=350, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,5,-2}, rotation={0,0,0}, height=250, width=600, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * 4 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={1.5,5,2}, rotation={0,0,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.2,5,2}, rotation={0,0,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-3.5,5,2}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Clicker", click_function="buttonClick_place", function_owner=self, + position={4.2,1,0}, rotation={0,0,0}, height=500, width=1100, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Counter", click_function="buttonClick_recall", function_owner=self, + position={-4.2,1,-0.1}, rotation={0,0,0}, height=500, width=1300, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-6,1,0}, rotation={0,90,0}, height=500, width=1200, +-- font_size=350, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Doom counter 19768a.ttslua b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Doom counter 19768a.ttslua index ee5b7a827..7aacde2cb 100644 --- a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Doom counter 19768a.ttslua +++ b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Doom counter 19768a.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {1,1,1,95} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {1,1,1,95} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 3f22e5.ttslua b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 3f22e5.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 3f22e5.ttslua +++ b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 3f22e5.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 4111de.ttslua b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 4111de.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 4111de.ttslua +++ b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 4111de.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 891403.ttslua b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 891403.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 891403.ttslua +++ b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources 891403.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources db85d6.ttslua b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources db85d6.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources db85d6.ttslua +++ b/unpacked/Custom_Model_Bag Clue Counter Swapper d919d6/Custom_Token Resources db85d6.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Delta Green Convergence Custom Investigators 84be1d.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Delta Green Convergence Custom Investigators 84be1d.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Delta Green Convergence Custom Investigators 84be1d.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Delta Green Convergence Custom Investigators 84be1d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Gender Swapped Investigators 33272e.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Gender Swapped Investigators 33272e.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Gender Swapped Investigators 33272e.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Gender Swapped Investigators 33272e.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Idol Thoughts Custom Investigators 991ff9.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Idol Thoughts Custom Investigators 991ff9.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Idol Thoughts Custom Investigators 991ff9.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Idol Thoughts Custom Investigators 991ff9.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Investigators fba392.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Investigators fba392.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Investigators fba392.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Investigators fba392.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Player Cards 64ad17.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Player Cards 64ad17.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Player Cards 64ad17.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Kaimonogatari Custom Investigators and Player Cards 54bd65/Custom_Model_Bag Player Cards 64ad17.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Pokemon Eldritch Edition Custom Investigators 1fb7ce.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Pokemon Eldritch Edition Custom Investigators 1fb7ce.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Pokemon Eldritch Edition Custom Investigators 1fb7ce.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Pokemon Eldritch Edition Custom Investigators 1fb7ce.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Strange Aeons Custom Investigators 991ff9.ttslua b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Strange Aeons Custom Investigators 991ff9.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Strange Aeons Custom Investigators 991ff9.ttslua +++ b/unpacked/Custom_Model_Bag Community-Created Investigators ed4ca7/Custom_Model_Bag Strange Aeons Custom Investigators 991ff9.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Core 2585f4.ttslua b/unpacked/Custom_Model_Bag Core 2585f4.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag Core 2585f4.ttslua +++ b/unpacked/Custom_Model_Bag Core 2585f4.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Core 64a613.ttslua b/unpacked/Custom_Model_Bag Core 64a613.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag Core 64a613.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111/Custom_Tile Core Difficulty 92d5f1.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111/Custom_Tile Core Difficulty 92d5f1.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111/Custom_Tile Core Difficulty 92d5f1.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 1 The Gathering 667111/Custom_Tile Core Difficulty 92d5f1.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96/Custom_Tile Core Set 8112ff.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96/Custom_Tile Core Set 8112ff.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96/Custom_Tile Core Set 8112ff.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 2 The Midnight Masks c38c96/Custom_Tile Core Set 8112ff.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0/Custom_Tile The Devourer Below 37feeb.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0/Custom_Tile The Devourer Below 37feeb.ttslua index 5d1d47cbd..a4eeff852 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0/Custom_Tile The Devourer Below 37feeb.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Model_Bag 3 The Devourer Below 2130f0/Custom_Tile The Devourer Below 37feeb.ttslua @@ -1,21 +1,21 @@ -name = 'The Devourer Below' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Devourer Below' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Core 64a613/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua b/unpacked/Custom_Model_Bag Core 64a613/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua index a86ae03a8..40b104bf0 100644 --- a/unpacked/Custom_Model_Bag Core 64a613/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua +++ b/unpacked/Custom_Model_Bag Core 64a613/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua @@ -1,679 +1,679 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --First checkbox - { - pos = {-0.62,0.1,0.056}, - size = 400, - state = false - }, - --Second checkbox - { - pos = {-0.629,0.1,0.199}, - size = 400, - state = false - }, - --Third checkbox - { - pos = {-0.594,0.1,0.355}, - size = 400, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Killed Textbox - { - pos = {-0.4,0.1,0.68}, - rows = 8, - width = 3800, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {0.507,0.1,0.15}, - rows = 8, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Cultists interrogated - { - pos = {0.507,0.1,0.509}, - rows = 4, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Cultists got away - { - pos = {0.507,0.1,0.771}, - rows = 4, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --First checkbox + { + pos = {-0.62,0.1,0.056}, + size = 400, + state = false + }, + --Second checkbox + { + pos = {-0.629,0.1,0.199}, + size = 400, + state = false + }, + --Third checkbox + { + pos = {-0.594,0.1,0.355}, + size = 400, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Killed Textbox + { + pos = {-0.4,0.1,0.68}, + rows = 8, + width = 3800, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {0.507,0.1,0.15}, + rows = 8, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Cultists interrogated + { + pos = {0.507,0.1,0.509}, + rows = 4, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Cultists got away + { + pos = {0.507,0.1,0.771}, + rows = 4, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard b7af99.ttslua b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard b7af99.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard b7af99.ttslua +++ b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard b7af99.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard e19c97.ttslua b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard e19c97.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard e19c97.ttslua +++ b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Eternal Slumber 4403c4/Custom_Token Scenario - EasyStandard e19c97.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - EasyStandard 535979.ttslua b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - EasyStandard 535979.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - EasyStandard 535979.ttslua +++ b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - EasyStandard 535979.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - HardExpert 9ed124.ttslua b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - HardExpert 9ed124.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - HardExpert 9ed124.ttslua +++ b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag Standalone ce36ec/Bag Guardians of the Abyss 0a3b78/Bag The Night's Usurper 7cf77a/Custom_Token Scenario - HardExpert 9ed124.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario 2da146.ttslua b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario 2da146.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario 2da146.ttslua +++ b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario 2da146.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario dd61f1.ttslua b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario dd61f1.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario dd61f1.ttslua +++ b/unpacked/Custom_Model_Bag Encounter Sets fcfa7f/Bag The Forgotten Age 9dc850/Bag The Depths of Yoth 7f0a6d/Custom_Token Scenario dd61f1.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Guardian 1d802b.ttslua b/unpacked/Custom_Model_Bag Guardian 1d802b.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Guardian 1d802b.ttslua +++ b/unpacked/Custom_Model_Bag Guardian 1d802b.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Guardian 1d802b/Custom_Model_Bag Guardian bc3210.ttslua b/unpacked/Custom_Model_Bag Guardian 1d802b/Custom_Model_Bag Guardian bc3210.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Guardian 1d802b/Custom_Model_Bag Guardian bc3210.ttslua +++ b/unpacked/Custom_Model_Bag Guardian 1d802b/Custom_Model_Bag Guardian bc3210.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Guardian cd002a.ttslua b/unpacked/Custom_Model_Bag Guardian cd002a.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Guardian cd002a.ttslua +++ b/unpacked/Custom_Model_Bag Guardian cd002a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Guardian cd002a/Custom_Model_Bag Guardian a3401d.ttslua b/unpacked/Custom_Model_Bag Guardian cd002a/Custom_Model_Bag Guardian a3401d.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Guardian cd002a/Custom_Model_Bag Guardian a3401d.ttslua +++ b/unpacked/Custom_Model_Bag Guardian cd002a/Custom_Model_Bag Guardian a3401d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Maximillion Pegasus Custom Investigator 84be1d.ttslua b/unpacked/Custom_Model_Bag Maximillion Pegasus Custom Investigator 84be1d.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Maximillion Pegasus Custom Investigator 84be1d.ttslua +++ b/unpacked/Custom_Model_Bag Maximillion Pegasus Custom Investigator 84be1d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef.ttslua b/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef.ttslua +++ b/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef/Custom_Model Custom Data Helper aa3d8a.ttslua b/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef/Custom_Model Custom Data Helper aa3d8a.ttslua index ca858aa9a..42affc223 100644 --- a/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef/Custom_Model Custom Data Helper aa3d8a.ttslua +++ b/unpacked/Custom_Model_Bag Miskatonic Mouse 0954ef/Custom_Model Custom Data Helper aa3d8a.ttslua @@ -1,38 +1,38 @@ --- set true to enable debug logging -DEBUG = false - -function log(message) - if DEBUG then - print(message) - end -end - ---[[ -Known locations and clues. We check this to determine if we should -atttempt to spawn clues, first we look for _ and if -we find nothing we look for -format is [location_guid -> clueCount] -]] -LOCATIONS_DATA_JSON = [[ -{ - "Park Entrance": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Main Street, U.S.A.": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Park Entrance": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "The Hub": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Adventureland": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Frontierland": {"type": "fixed", "value": 3, "clueSide": "front"}, - "New Orleans Square": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Critter Country": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Galaxy's Edge": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Fantasyland": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Toontown": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Tomorrowland": {"type": "fixed", "value": 3, "clueSide": "front"} -} -]] - -LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) - -function onload(save_state) - local playArea = getObjectFromGUID('721ba2') - playArea.call("updateLocations", {self.getGUID()}) -end +-- set true to enable debug logging +DEBUG = false + +function log(message) + if DEBUG then + print(message) + end +end + +--[[ +Known locations and clues. We check this to determine if we should +atttempt to spawn clues, first we look for _ and if +we find nothing we look for +format is [location_guid -> clueCount] +]] +LOCATIONS_DATA_JSON = [[ +{ + "Park Entrance": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Main Street, U.S.A.": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Park Entrance": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "The Hub": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Adventureland": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Frontierland": {"type": "fixed", "value": 3, "clueSide": "front"}, + "New Orleans Square": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Critter Country": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Galaxy's Edge": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Fantasyland": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Toontown": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Tomorrowland": {"type": "fixed", "value": 3, "clueSide": "front"} +} +]] + +LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) + +function onload(save_state) + local playArea = getObjectFromGUID('721ba2') + playArea.call("updateLocations", {self.getGUID()}) +end diff --git a/unpacked/Custom_Model_Bag Mystic 6117a1.ttslua b/unpacked/Custom_Model_Bag Mystic 6117a1.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Mystic 6117a1.ttslua +++ b/unpacked/Custom_Model_Bag Mystic 6117a1.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Mystic 6117a1/Custom_Model_Bag Mystic 2c2b99.ttslua b/unpacked/Custom_Model_Bag Mystic 6117a1/Custom_Model_Bag Mystic 2c2b99.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Mystic 6117a1/Custom_Model_Bag Mystic 2c2b99.ttslua +++ b/unpacked/Custom_Model_Bag Mystic 6117a1/Custom_Model_Bag Mystic 2c2b99.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Mystic b4d9bf.ttslua b/unpacked/Custom_Model_Bag Mystic b4d9bf.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Mystic b4d9bf.ttslua +++ b/unpacked/Custom_Model_Bag Mystic b4d9bf.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Mystic b4d9bf/Custom_Model_Bag Mystic ee21f7.ttslua b/unpacked/Custom_Model_Bag Mystic b4d9bf/Custom_Model_Bag Mystic ee21f7.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Mystic b4d9bf/Custom_Model_Bag Mystic ee21f7.ttslua +++ b/unpacked/Custom_Model_Bag Mystic b4d9bf/Custom_Model_Bag Mystic ee21f7.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Neutral a4d0e8.ttslua b/unpacked/Custom_Model_Bag Neutral a4d0e8.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Neutral a4d0e8.ttslua +++ b/unpacked/Custom_Model_Bag Neutral a4d0e8.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Neutral a4d0e8/Custom_Model_Bag Neutral 06b03b.ttslua b/unpacked/Custom_Model_Bag Neutral a4d0e8/Custom_Model_Bag Neutral 06b03b.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Neutral a4d0e8/Custom_Model_Bag Neutral 06b03b.ttslua +++ b/unpacked/Custom_Model_Bag Neutral a4d0e8/Custom_Model_Bag Neutral 06b03b.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Neutral aef7dd.ttslua b/unpacked/Custom_Model_Bag Neutral aef7dd.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Neutral aef7dd.ttslua +++ b/unpacked/Custom_Model_Bag Neutral aef7dd.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Neutral aef7dd/Custom_Model_Bag Neutral 574514.ttslua b/unpacked/Custom_Model_Bag Neutral aef7dd/Custom_Model_Bag Neutral 574514.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Neutral aef7dd/Custom_Model_Bag Neutral 574514.ttslua +++ b/unpacked/Custom_Model_Bag Neutral aef7dd/Custom_Model_Bag Neutral 574514.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Neutral c5261f.ttslua b/unpacked/Custom_Model_Bag Neutral c5261f.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Neutral c5261f.ttslua +++ b/unpacked/Custom_Model_Bag Neutral c5261f.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Neutral c5261f/Custom_Model_Bag Neutral 3fe354.ttslua b/unpacked/Custom_Model_Bag Neutral c5261f/Custom_Model_Bag Neutral 3fe354.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Neutral c5261f/Custom_Model_Bag Neutral 3fe354.ttslua +++ b/unpacked/Custom_Model_Bag Neutral c5261f/Custom_Model_Bag Neutral 3fe354.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Promo Investigators 5fe24e.ttslua b/unpacked/Custom_Model_Bag Promo Investigators 5fe24e.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag Promo Investigators 5fe24e.ttslua +++ b/unpacked/Custom_Model_Bag Promo Investigators 5fe24e.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130.ttslua index b855e99ad..7ba1823d7 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130.ttslua @@ -1,504 +1,504 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e/Custom_Tile The Dunwich Legacy a74352.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e/Custom_Tile The Dunwich Legacy a74352.ttslua index cfa110e20..39ecc5466 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e/Custom_Tile The Dunwich Legacy a74352.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1a Extracurricular Activity d33f7e/Custom_Tile The Dunwich Legacy a74352.ttslua @@ -1,21 +1,21 @@ -name = 'The Dunwich Legacy' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Dunwich Legacy' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082/Custom_Tile The Dunwich Legacy 1d6227.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082/Custom_Tile The Dunwich Legacy 1d6227.ttslua index cfa110e20..39ecc5466 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082/Custom_Tile The Dunwich Legacy 1d6227.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 1b The House Always Wins f52082/Custom_Tile The Dunwich Legacy 1d6227.ttslua @@ -1,21 +1,21 @@ -name = 'The Dunwich Legacy' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Dunwich Legacy' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a/Custom_Tile The Miskatonic Museum 4b5e17.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a/Custom_Tile The Miskatonic Museum 4b5e17.ttslua index f92a55f33..ca89f18f6 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a/Custom_Tile The Miskatonic Museum 4b5e17.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 2 The Miskatonic Museum 87897a/Custom_Tile The Miskatonic Museum 4b5e17.ttslua @@ -1,25 +1,25 @@ -name = 'The Miskatonic Museum' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Miskatonic Museum' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86/Custom_Tile The Essex County Express 247967.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86/Custom_Tile The Essex County Express 247967.ttslua index 8942d6ff8..9ff549176 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86/Custom_Tile The Essex County Express 247967.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 3 The Essex County Express d92b86/Custom_Tile The Essex County Express 247967.ttslua @@ -1,25 +1,25 @@ -name = 'The Essex County Express' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Essex County Express' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7/Custom_Tile Blood on the Altar 92b54a.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7/Custom_Tile Blood on the Altar 92b54a.ttslua index 35359436c..b50b2762f 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7/Custom_Tile Blood on the Altar 92b54a.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 4 Blood on the Altar 1536e7/Custom_Tile Blood on the Altar 92b54a.ttslua @@ -1,25 +1,25 @@ -name = 'Blood on the Altar' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Blood on the Altar' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde/Custom_Tile Undimensioned and Unseen 393c71.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde/Custom_Tile Undimensioned and Unseen 393c71.ttslua index 796c0adfa..4da502b94 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde/Custom_Tile Undimensioned and Unseen 393c71.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 5 Undimensioned and Unseen a82dde/Custom_Tile Undimensioned and Unseen 393c71.ttslua @@ -1,25 +1,25 @@ -name = 'Undimensioned and Unseen' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Undimensioned and Unseen' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29/Custom_Tile Where Doom Awaits a621ae.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29/Custom_Tile Where Doom Awaits a621ae.ttslua index c8658d789..5f3588cb8 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29/Custom_Tile Where Doom Awaits a621ae.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 6 Where Doom Awaits 175a29/Custom_Tile Where Doom Awaits a621ae.ttslua @@ -1,25 +1,25 @@ -name = 'Where Doom Awaits' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Where Doom Awaits' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b/Custom_Tile Lost in Time and Space 64a607.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b/Custom_Tile Lost in Time and Space 64a607.ttslua index a649f8c03..09337160a 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b/Custom_Tile Lost in Time and Space 64a607.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Model_Bag 7 Lost in Time and Space 1fca6b/Custom_Tile Lost in Time and Space 64a607.ttslua @@ -1,25 +1,25 @@ -name = 'Lost in Time and Space' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Lost in Time and Space' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua index 690a83709..3d43d4f4c 100644 --- a/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Dunwich Legacy ce9130/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua @@ -1,669 +1,669 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --First checkbox --- { --- pos = {-0.62,0.1,0.056}, --- size = 400, --- state = false --- }, - --Second checkbox --- { --- pos = {-0.629,0.1,0.199}, --- size = 400, --- state = false --- }, - --Third checkbox --- { --- pos = {-0.594,0.1,0.355}, --- size = 400, --- state = false --- }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.45,0.1,0.55}, - rows =18, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.384,0.1,0.228}, - rows = 8, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Cultists interrogated - { - pos = {0.384,0.1,0.69}, - rows = 8, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --First checkbox +-- { +-- pos = {-0.62,0.1,0.056}, +-- size = 400, +-- state = false +-- }, + --Second checkbox +-- { +-- pos = {-0.629,0.1,0.199}, +-- size = 400, +-- state = false +-- }, + --Third checkbox +-- { +-- pos = {-0.594,0.1,0.355}, +-- size = 400, +-- state = false +-- }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.45,0.1,0.55}, + rows =18, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.384,0.1,0.228}, + rows = 8, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Cultists interrogated + { + pos = {0.384,0.1,0.69}, + rows = 8, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3.ttslua index b855e99ad..7ba1823d7 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3.ttslua @@ -1,504 +1,504 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2/Custom_Tile The Forgotten Age e95200.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2/Custom_Tile The Forgotten Age e95200.ttslua index 75c4561fb..200437b6c 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2/Custom_Tile The Forgotten Age e95200.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 1 Return to The Untamed Wilds 85a0c2/Custom_Tile The Forgotten Age e95200.ttslua @@ -1,21 +1,21 @@ -name = 'The Forgotten Age' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Forgotten Age' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2/Custom_Tile The Doom of Eztli 294ec4.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2/Custom_Tile The Doom of Eztli 294ec4.ttslua index 25a046b6a..5672c33bc 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2/Custom_Tile The Doom of Eztli 294ec4.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 2 Return to The Doom of Eztli 110ce2/Custom_Tile The Doom of Eztli 294ec4.ttslua @@ -1,25 +1,25 @@ -name = 'The Doom of Eztli' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Doom of Eztli' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940/Custom_Tile Threads of Fate 7a95f6.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940/Custom_Tile Threads of Fate 7a95f6.ttslua index aa256f497..0d6a8bd42 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940/Custom_Tile Threads of Fate 7a95f6.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 3 Return to Threads of Fate 499940/Custom_Tile Threads of Fate 7a95f6.ttslua @@ -1,25 +1,25 @@ -name = 'Threads of Fate' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Threads of Fate' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4/Custom_Tile The Boundary Beyond 010761.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4/Custom_Tile The Boundary Beyond 010761.ttslua index 88130bf52..f46c523bf 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4/Custom_Tile The Boundary Beyond 010761.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 4 Return to The Boundary Beyond 952af4/Custom_Tile The Boundary Beyond 010761.ttslua @@ -1,25 +1,25 @@ -name = 'The Boundary Beyond' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Boundary Beyond' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f/Custom_Tile Heart of the Elders 493cb1.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f/Custom_Tile Heart of the Elders 493cb1.ttslua index 4f3609807..5a7299c73 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f/Custom_Tile Heart of the Elders 493cb1.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 1 5abc8f/Custom_Tile Heart of the Elders 493cb1.ttslua @@ -1,25 +1,25 @@ -name = 'Heart of the Elders' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Heart of the Elders' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 2 3ccabf.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 2 3ccabf.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 2 3ccabf.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 5 Return to Heart of the Elders Part 2 3ccabf.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427/Custom_Tile The City of Archives 2fb6dc.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427/Custom_Tile The City of Archives 2fb6dc.ttslua index 787f8705f..3224092d4 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427/Custom_Tile The City of Archives 2fb6dc.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 6 Return to The City of Archives e73427/Custom_Tile The City of Archives 2fb6dc.ttslua @@ -1,25 +1,25 @@ -name = 'The City of Archives' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The City of Archives' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Tile The Depths of Yoth 7aa4e3.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Tile The Depths of Yoth 7aa4e3.ttslua index 7d9affdc4..e569e19b2 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Tile The Depths of Yoth 7aa4e3.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Tile The Depths of Yoth 7aa4e3.ttslua @@ -1,25 +1,25 @@ -name = 'The Depths of Yoth' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Depths of Yoth' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - EasyStandard dd61f1.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - EasyStandard dd61f1.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - EasyStandard dd61f1.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - EasyStandard dd61f1.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - HardExpert 2da146.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - HardExpert 2da146.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - HardExpert 2da146.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 7 Return to The Depths of Yoth 9c986e/Custom_Token Scenario - HardExpert 2da146.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7/Custom_Tile Shattered Aeons 6dc72a.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7/Custom_Tile Shattered Aeons 6dc72a.ttslua index b78ce3eb4..b31a42434 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7/Custom_Tile Shattered Aeons 6dc72a.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 8 Return to Shattered Aeons 5e83e7/Custom_Tile Shattered Aeons 6dc72a.ttslua @@ -1,21 +1,21 @@ -name = 'Shattered Aeons' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Shattered Aeons' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 9 Return to Secret Scenario 496395.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 9 Return to Secret Scenario 496395.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 9 Return to Secret Scenario 496395.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Model_Bag 9 Return to Secret Scenario 496395.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua index 3e3ff898f..682c9d34c 100644 --- a/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Forgotten Age 479ff3/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua @@ -1,691 +1,691 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Yig's Fury - { - pos = {0.097,0.1,0.88}, - size = 500, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one Supplies - { - pos = {-0.637,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two supplies - { - pos = {-0.2,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three supplies - { - pos = {0.24,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four supplies - { - pos = {0.671,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.475,0.1,0.62}, - rows =12, - width = 3200, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.527,0.1,0.507}, - rows = 12, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Yig's Fury + { + pos = {0.097,0.1,0.88}, + size = 500, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one Supplies + { + pos = {-0.637,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two supplies + { + pos = {-0.2,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three supplies + { + pos = {0.24,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four supplies + { + pos = {0.671,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.475,0.1,0.62}, + rows =12, + width = 3200, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.527,0.1,0.507}, + rows = 12, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a.ttslua index b855e99ad..7ba1823d7 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a.ttslua @@ -1,504 +1,504 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua index 978a9d2b5..7878134ac 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua @@ -1,21 +1,21 @@ -name = 'The Path to Carcosa' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Path to Carcosa' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua index c9acd00d0..80ce317d3 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua @@ -1,25 +1,25 @@ -name = 'The Last King' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Last King' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua index 9852aeb27..fd833106f 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua @@ -1,25 +1,25 @@ -name = 'Echoes of the Past' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Echoes of the Past' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua index f7109dddb..e78b2e78a 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua @@ -1,25 +1,25 @@ -name = 'The Unspeakable Oath' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Unspeakable Oath' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua index e092a5769..bacd5051f 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua @@ -1,25 +1,25 @@ -name = 'A Phantom of Truth' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'A Phantom of Truth' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua index 9607689ac..c36627e17 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua @@ -1,25 +1,25 @@ -name = 'The Pallid Mask' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Pallid Mask' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua index 78350373e..a505ccca6 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua @@ -1,25 +1,25 @@ -name = 'Black Stars Rise' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Black Stars Rise' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua index 710b4a84e..ffa409a5f 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua @@ -1,25 +1,25 @@ -name = 'Dim Carcosa' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Dim Carcosa' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Tile Carcosa Campaign Log ae8317.ttslua b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Tile Carcosa Campaign Log ae8317.ttslua index 108024431..7a861eb36 100644 --- a/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Tile Carcosa Campaign Log ae8317.ttslua +++ b/unpacked/Custom_Model_Bag Return to The Path to Carcosa e9889a/Custom_Tile Carcosa Campaign Log ae8317.ttslua @@ -1,755 +1,755 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --Doubt 1 - { - pos = {-0.482,0.1,0.776}, - size = 200, - state = false - }, - --Doubt 2 - { - pos = {-0.43,0.1,0.776}, - size = 200, - state = false - }, - --Doubt 3 - { - pos = {-0.38,0.1,0.775}, - size = 200, - state = false - }, - --Doubt 4 - { - pos = {-0.325,0.1,0.778}, - size = 200, - state = false - }, - --Doubt 5 - { - pos = {-0.27,0.1,0.779}, - size = 200, - state = false - }, - --Doubt 6 - { - pos = {-0.219,0.1,0.778}, - size = 200, - state = false - }, - --Doubt 7 - { - pos = {-0.168,0.1,0.782}, - size = 200, - state = false - }, - --Doubt 8 - { - pos = {-0.111,0.1,0.783}, - size = 200, - state = false - }, - --Conviction 1 - { - pos = {-0.736,0.1,0.868}, - size = 200, - state = false - }, - --Conviction 2 - { - pos = {-0.68,0.1,0.869}, - size = 200, - state = false - }, - --Conviction 3 - { - pos = {-0.626,0.1,0.869}, - size = 200, - state = false - }, - --Conviction 4 - { - pos = {-0.574,0.1,0.874}, - size = 200, - state = false - }, - --Conviction 5 - { - pos = {-0.519,0.1,0.874}, - size = 200, - state = false - }, - --Conviction 6 - { - pos = {-0.467,0.1,0.879}, - size = 200, - state = false - }, - --Conviction 7 - { - pos = {-0.416,0.1,0.876}, - size = 200, - state = false - }, - --Conviction 8 - { - pos = {-0.357,0.1,0.879}, - size = 200, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Chasing The Stranger - { - pos = {0.414,0.1,0.106}, - size = 500, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.38,0.1,0.339}, - rows =16, - width = 3200, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --VIPs Interviewed - { - pos = {0.43,0.1,0.338}, - rows = 6, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --VIPs Slain - { - pos = {0.43,0.1,0.643}, - rows = 6, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --Doubt 1 + { + pos = {-0.482,0.1,0.776}, + size = 200, + state = false + }, + --Doubt 2 + { + pos = {-0.43,0.1,0.776}, + size = 200, + state = false + }, + --Doubt 3 + { + pos = {-0.38,0.1,0.775}, + size = 200, + state = false + }, + --Doubt 4 + { + pos = {-0.325,0.1,0.778}, + size = 200, + state = false + }, + --Doubt 5 + { + pos = {-0.27,0.1,0.779}, + size = 200, + state = false + }, + --Doubt 6 + { + pos = {-0.219,0.1,0.778}, + size = 200, + state = false + }, + --Doubt 7 + { + pos = {-0.168,0.1,0.782}, + size = 200, + state = false + }, + --Doubt 8 + { + pos = {-0.111,0.1,0.783}, + size = 200, + state = false + }, + --Conviction 1 + { + pos = {-0.736,0.1,0.868}, + size = 200, + state = false + }, + --Conviction 2 + { + pos = {-0.68,0.1,0.869}, + size = 200, + state = false + }, + --Conviction 3 + { + pos = {-0.626,0.1,0.869}, + size = 200, + state = false + }, + --Conviction 4 + { + pos = {-0.574,0.1,0.874}, + size = 200, + state = false + }, + --Conviction 5 + { + pos = {-0.519,0.1,0.874}, + size = 200, + state = false + }, + --Conviction 6 + { + pos = {-0.467,0.1,0.879}, + size = 200, + state = false + }, + --Conviction 7 + { + pos = {-0.416,0.1,0.876}, + size = 200, + state = false + }, + --Conviction 8 + { + pos = {-0.357,0.1,0.879}, + size = 200, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Chasing The Stranger + { + pos = {0.414,0.1,0.106}, + size = 500, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.38,0.1,0.339}, + rows =16, + width = 3200, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --VIPs Interviewed + { + pos = {0.43,0.1,0.338}, + rows = 6, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --VIPs Slain + { + pos = {0.43,0.1,0.643}, + rows = 6, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d.ttslua index b855e99ad..7ba1823d7 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d.ttslua @@ -1,504 +1,504 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, - font_size=150, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, - font_size=150, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, - font_size=200, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,1,-2}, rotation={0,0,0}, height=240, width=500, - font_size=150, color={0,0,0}, font_color={1,1,1} - }) - ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.2,1,-2}, rotation={0,0,0}, height=240, width=570, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={-1.2,1,2}, rotation={0,0,0}, height=240, width=550, + font_size=150, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.3,1,2}, rotation={0,0,0}, height=240, width=600, + font_size=150, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={1.2,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.7,1,2}, rotation={0,0,0}, height=280, width=600, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.7,1,2}, rotation={0,0,0}, height=280, width=650, + font_size=200, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,1,-2}, rotation={0,0,0}, height=240, width=500, + font_size=150, color={0,0,0}, font_color={1,1,1} + }) + +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8/Custom_Tile Core Difficulty 527f29.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8/Custom_Tile Core Difficulty 527f29.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8/Custom_Tile Core Difficulty 527f29.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 1 Return to The Gathering 41ebd8/Custom_Tile Core Difficulty 527f29.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c.ttslua index 34e9ba52b..d3a73c99a 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c/Custom_Tile Core Difficulty 47f3de.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c/Custom_Tile Core Difficulty 47f3de.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c/Custom_Tile Core Difficulty 47f3de.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 2 Return to The Midnight Masks bcc86c/Custom_Tile Core Difficulty 47f3de.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 3 Return to The Devourer Below 604753.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 3 Return to The Devourer Below 604753.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 3 Return to The Devourer Below 604753.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Model_Bag 3 Return to The Devourer Below 604753.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua index a86ae03a8..40b104bf0 100644 --- a/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua +++ b/unpacked/Custom_Model_Bag Return to the Night of the Zealot 56270d/Custom_Tile Night of the Zealot Campaign Log e0c3e7.ttslua @@ -1,679 +1,679 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --First checkbox - { - pos = {-0.62,0.1,0.056}, - size = 400, - state = false - }, - --Second checkbox - { - pos = {-0.629,0.1,0.199}, - size = 400, - state = false - }, - --Third checkbox - { - pos = {-0.594,0.1,0.355}, - size = 400, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.4}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.5}, - size = 300, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.66}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.58}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.28}, - rows = 3, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Killed Textbox - { - pos = {-0.4,0.1,0.68}, - rows = 8, - width = 3800, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {0.507,0.1,0.15}, - rows = 8, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Cultists interrogated - { - pos = {0.507,0.1,0.509}, - rows = 4, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Cultists got away - { - pos = {0.507,0.1,0.771}, - rows = 4, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --First checkbox + { + pos = {-0.62,0.1,0.056}, + size = 400, + state = false + }, + --Second checkbox + { + pos = {-0.629,0.1,0.199}, + size = 400, + state = false + }, + --Third checkbox + { + pos = {-0.594,0.1,0.355}, + size = 400, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.4}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.5}, + size = 300, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.66}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.58}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.28}, + rows = 3, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Killed Textbox + { + pos = {-0.4,0.1,0.68}, + rows = 8, + width = 3800, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {0.507,0.1,0.15}, + rows = 8, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Cultists interrogated + { + pos = {0.507,0.1,0.509}, + rows = 4, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Cultists got away + { + pos = {0.507,0.1,0.771}, + rows = 4, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Rogue 68d7b8.ttslua b/unpacked/Custom_Model_Bag Rogue 68d7b8.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Rogue 68d7b8.ttslua +++ b/unpacked/Custom_Model_Bag Rogue 68d7b8.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Rogue 68d7b8/Custom_Model_Bag Rogue 21d547.ttslua b/unpacked/Custom_Model_Bag Rogue 68d7b8/Custom_Model_Bag Rogue 21d547.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Rogue 68d7b8/Custom_Model_Bag Rogue 21d547.ttslua +++ b/unpacked/Custom_Model_Bag Rogue 68d7b8/Custom_Model_Bag Rogue 21d547.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Rogue deaa6d.ttslua b/unpacked/Custom_Model_Bag Rogue deaa6d.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Rogue deaa6d.ttslua +++ b/unpacked/Custom_Model_Bag Rogue deaa6d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Rogue deaa6d/Custom_Model_Bag Rogue fa4d49.ttslua b/unpacked/Custom_Model_Bag Rogue deaa6d/Custom_Model_Bag Rogue fa4d49.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Rogue deaa6d/Custom_Model_Bag Rogue fa4d49.ttslua +++ b/unpacked/Custom_Model_Bag Rogue deaa6d/Custom_Model_Bag Rogue fa4d49.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Seeker 1e7fc5.ttslua b/unpacked/Custom_Model_Bag Seeker 1e7fc5.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Seeker 1e7fc5.ttslua +++ b/unpacked/Custom_Model_Bag Seeker 1e7fc5.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Seeker 1e7fc5/Custom_Model_Bag Seeker e328ea.ttslua b/unpacked/Custom_Model_Bag Seeker 1e7fc5/Custom_Model_Bag Seeker e328ea.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Seeker 1e7fc5/Custom_Model_Bag Seeker e328ea.ttslua +++ b/unpacked/Custom_Model_Bag Seeker 1e7fc5/Custom_Model_Bag Seeker e328ea.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Seeker 5ec2fb.ttslua b/unpacked/Custom_Model_Bag Seeker 5ec2fb.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Seeker 5ec2fb.ttslua +++ b/unpacked/Custom_Model_Bag Seeker 5ec2fb.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Seeker 5ec2fb/Custom_Model_Bag Seeker d99b16.ttslua b/unpacked/Custom_Model_Bag Seeker 5ec2fb/Custom_Model_Bag Seeker d99b16.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Seeker 5ec2fb/Custom_Model_Bag Seeker d99b16.ttslua +++ b/unpacked/Custom_Model_Bag Seeker 5ec2fb/Custom_Model_Bag Seeker d99b16.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Starter Deck Investigators 35fb9c.ttslua b/unpacked/Custom_Model_Bag Starter Deck Investigators 35fb9c.ttslua index 39c42d572..1fb1508eb 100644 --- a/unpacked/Custom_Model_Bag Starter Deck Investigators 35fb9c.ttslua +++ b/unpacked/Custom_Model_Bag Starter Deck Investigators 35fb9c.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor +12 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=800, width=800, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor +12 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=800, width=800, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Survivor 9c814b.ttslua b/unpacked/Custom_Model_Bag Survivor 9c814b.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Survivor 9c814b.ttslua +++ b/unpacked/Custom_Model_Bag Survivor 9c814b.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Survivor 9c814b/Custom_Model_Bag Survivor 3c40d9.ttslua b/unpacked/Custom_Model_Bag Survivor 9c814b/Custom_Model_Bag Survivor 3c40d9.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Survivor 9c814b/Custom_Model_Bag Survivor 3c40d9.ttslua +++ b/unpacked/Custom_Model_Bag Survivor 9c814b/Custom_Model_Bag Survivor 3c40d9.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Survivor c02830.ttslua b/unpacked/Custom_Model_Bag Survivor c02830.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Survivor c02830.ttslua +++ b/unpacked/Custom_Model_Bag Survivor c02830.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Survivor c02830/Custom_Model_Bag Survivor f15fc1.ttslua b/unpacked/Custom_Model_Bag Survivor c02830/Custom_Model_Bag Survivor f15fc1.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Survivor c02830/Custom_Model_Bag Survivor f15fc1.ttslua +++ b/unpacked/Custom_Model_Bag Survivor c02830/Custom_Model_Bag Survivor f15fc1.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 0dcbe8.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 0dcbe8.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 0dcbe8.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 0dcbe8.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775.ttslua index ed7a62e7d..45f110e8b 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775/Custom_Tile The Circle Undone f697b0.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775/Custom_Tile The Circle Undone f697b0.ttslua index 47d018ac8..624750c7f 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775/Custom_Tile The Circle Undone f697b0.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 1 The Witching Hour 67a775/Custom_Tile The Circle Undone f697b0.ttslua @@ -1,21 +1,21 @@ -name = 'The Circle Undone' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Circle Undone' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc/Custom_Tile At Death's Doorstep b21125.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc/Custom_Tile At Death's Doorstep b21125.ttslua index 629fbd0e7..920788446 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc/Custom_Tile At Death's Doorstep b21125.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 2 At Death's Doorstep 7388bc/Custom_Tile At Death's Doorstep b21125.ttslua @@ -1,25 +1,25 @@ -name = "At Death's Doorstep" - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = "At Death's Doorstep" + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) end -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0.ttslua index 689030815..33f4391a1 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} ---w }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +--w }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0/Custom_Tile The Secret Name b21125.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0/Custom_Tile The Secret Name b21125.ttslua index 18a0d7f51..f9497f333 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0/Custom_Tile The Secret Name b21125.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 3 The Secret Name 5c79d0/Custom_Tile The Secret Name b21125.ttslua @@ -1,25 +1,25 @@ -name = 'The Secret Name' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Secret Name' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) end -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8.ttslua index ed7a62e7d..45f110e8b 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8/Custom_Tile The Wages of Sin b21125.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8/Custom_Tile The Wages of Sin b21125.ttslua index 1887450fa..512ea5569 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8/Custom_Tile The Wages of Sin b21125.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 4 The Wages of Sin 1e45e8/Custom_Tile The Wages of Sin b21125.ttslua @@ -1,25 +1,25 @@ -name = 'The Wages of Sin' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Wages of Sin' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) end -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48.ttslua index ed7a62e7d..45f110e8b 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Member of the Lodge 38a5f7.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Member of the Lodge 38a5f7.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Member of the Lodge 38a5f7.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Member of the Lodge 38a5f7.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Not a Member of the Lodge abe15f.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Not a Member of the Lodge abe15f.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Not a Member of the Lodge abe15f.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Bag Not a Member of the Lodge abe15f.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Custom_Tile For the Greater Good bbb70a.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Custom_Tile For the Greater Good bbb70a.ttslua index 0c455ba9f..4a23f1a51 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Custom_Tile For the Greater Good bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 5 For the Greater Good a61b48/Custom_Tile For the Greater Good bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'For the Greater Good' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'For the Greater Good' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a.ttslua index ed7a62e7d..45f110e8b 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a/Custom_Tile Union and Disillusion 3fe126.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a/Custom_Tile Union and Disillusion 3fe126.ttslua index a25904f3f..ce0e418ec 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a/Custom_Tile Union and Disillusion 3fe126.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 6 Union and Disillusion 20f70a/Custom_Tile Union and Disillusion 3fe126.ttslua @@ -1,25 +1,25 @@ -name = 'Union and Disillusion' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Union and Disillusion' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Anette Mason is posessed by evil d14543.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Anette Mason is posessed by evil d14543.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Anette Mason is posessed by evil d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Anette Mason is posessed by evil d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Carl Sanford possesses the secrets of the universe 92c6fc.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Carl Sanford possesses the secrets of the universe 92c6fc.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Carl Sanford possesses the secrets of the universe 92c6fc.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Bag Carl Sanford possesses the secrets of the universe 92c6fc.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Custom_Tile In the Clutches of Chaos e0709b.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Custom_Tile In the Clutches of Chaos e0709b.ttslua index 89aa66922..9f9470e13 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Custom_Tile In the Clutches of Chaos e0709b.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 7 In the Clutches of Chaos 1ee775/Custom_Tile In the Clutches of Chaos e0709b.ttslua @@ -1,25 +1,25 @@ -name = 'In the Clutches of Chaos' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'In the Clutches of Chaos' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66/Custom_Tile Before the Black Throne b16392.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66/Custom_Tile Before the Black Throne b16392.ttslua index 3d469943a..7b48da20b 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66/Custom_Tile Before the Black Throne b16392.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag 8 Before the Black Throne 0fad66/Custom_Tile Before the Black Throne b16392.ttslua @@ -1,25 +1,25 @@ -name = 'Before the Black Throne' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Before the Black Throne' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a/Custom_Tile The Circle Undone 05f912.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a/Custom_Tile The Circle Undone 05f912.ttslua index 47d018ac8..624750c7f 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a/Custom_Tile The Circle Undone 05f912.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Model_Bag Prologue Disappearance at the Twilight Estate 2f008a/Custom_Tile The Circle Undone 05f912.ttslua @@ -1,21 +1,21 @@ -name = 'The Circle Undone' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Circle Undone' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Tile The Circle Undone Campaign Log 1 44a05a.ttslua b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Tile The Circle Undone Campaign Log 1 44a05a.ttslua index 274e1d634..797b18e09 100644 --- a/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Tile The Circle Undone Campaign Log 1 44a05a.ttslua +++ b/unpacked/Custom_Model_Bag The Circle Undone 63e097/Custom_Tile The Circle Undone Campaign Log 1 44a05a.ttslua @@ -1,653 +1,653 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {0.902,0.886,0.788} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.50,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.06,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.27}, - rows = 10, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.27}, - rows = 10, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.62}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.268}, - rows = 10, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.62}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.265}, - rows = 10, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.464,0.1,0.507}, - rows =16, - width = 3200, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign NOtes 2 - { - pos = {0.344,0.1,0.187}, - rows = 10, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Mementos - { - pos = {0.351,0.1,0.744}, - rows = 12, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {0.902,0.886,0.788} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.50,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.06,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.27}, + rows = 10, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.27}, + rows = 10, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.62}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.268}, + rows = 10, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.62}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.265}, + rows = 10, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.464,0.1,0.507}, + rows =16, + width = 3200, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign NOtes 2 + { + pos = {0.344,0.1,0.187}, + rows = 10, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Mementos + { + pos = {0.351,0.1,0.744}, + rows = 12, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828/Custom_Tile Campaign A Setup 075016.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828/Custom_Tile Campaign A Setup 075016.ttslua index b26158ce8..af12e8963 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828/Custom_Tile Campaign A Setup 075016.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-A Beyond the Gates of Sleep 7f5828/Custom_Tile Campaign A Setup 075016.ttslua @@ -1,25 +1,25 @@ -name = 'TDE_A' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'TDE_A' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7.ttslua index ed7a62e7d..45f110e8b 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Model_Bag Set-aside a45247/Custom_Model_Bag Infestation Bag 0257a2.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Model_Bag Set-aside a45247/Custom_Model_Bag Infestation Bag 0257a2.ttslua index 3d2f7ab59..eba7fa0dc 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Model_Bag Set-aside a45247/Custom_Model_Bag Infestation Bag 0257a2.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Model_Bag Set-aside a45247/Custom_Model_Bag Infestation Bag 0257a2.ttslua @@ -1,5 +1,5 @@ -function onCollisionEnter(collision_info) - self.shuffle() - self.shuffle() - self.shuffle() +function onCollisionEnter(collision_info) + self.shuffle() + self.shuffle() + self.shuffle() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Tile Campaign B Setup bbb70a.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Tile Campaign B Setup bbb70a.ttslua index 4dde019f3..04f54ee0c 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Tile Campaign B Setup bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 1-B Waking Nightmare 599cb7/Custom_Tile Campaign B Setup bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'TDE_B' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'TDE_B' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca/Custom_Tile The Search For Kadath bbb70a.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca/Custom_Tile The Search For Kadath bbb70a.ttslua index 4cdcd8644..9e2b61d86 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca/Custom_Tile The Search For Kadath bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-A The Search For Kadath 7b07ca/Custom_Tile The Search For Kadath bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'The Search For Kadath' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Search For Kadath' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86/Custom_Tile A Thousand Shapes of Horror b53295.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86/Custom_Tile A Thousand Shapes of Horror b53295.ttslua index ba00854d4..cb91e7329 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86/Custom_Tile A Thousand Shapes of Horror b53295.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 2-B A Thousand Shapes of Horror 1b4f86/Custom_Tile A Thousand Shapes of Horror b53295.ttslua @@ -1,25 +1,25 @@ -name = 'A Thousand Shapes of Horror' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'A Thousand Shapes of Horror' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66/Custom_Tile Dark Side of the Moon aa8d82.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66/Custom_Tile Dark Side of the Moon aa8d82.ttslua index e562e4cb3..afe917f51 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66/Custom_Tile Dark Side of the Moon aa8d82.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-A Dark Side of the Moon 0fad66/Custom_Tile Dark Side of the Moon aa8d82.ttslua @@ -1,25 +1,25 @@ -name = 'Dark Side of the Moon' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Dark Side of the Moon' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf/Custom_Tile Point of No Return f302ab.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf/Custom_Tile Point of No Return f302ab.ttslua index eff41dc38..c08e0e3c9 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf/Custom_Tile Point of No Return f302ab.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 3-B Point of No Return 4f81cf/Custom_Tile Point of No Return f302ab.ttslua @@ -1,25 +1,25 @@ -name = 'Point of No Return' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Point of No Return' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096/Custom_Tile Point of No Return 3e86c2.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096/Custom_Tile Point of No Return 3e86c2.ttslua index 6e4f3527f..6f6daf608 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096/Custom_Tile Point of No Return 3e86c2.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-A Where the Gods Dwell 185096/Custom_Tile Point of No Return 3e86c2.ttslua @@ -1,25 +1,25 @@ -name = 'Where the Gods Dwell' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Where the Gods Dwell' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Model_Bag Set-aside 376a06/Bag Atlach-Nacha d14543.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Model_Bag Set-aside 376a06/Bag Atlach-Nacha d14543.ttslua index f82d90245..758efa0e2 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Model_Bag Set-aside 376a06/Bag Atlach-Nacha d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Model_Bag Set-aside 376a06/Bag Atlach-Nacha d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Setup", click_function="buttonClick_setup", function_owner=self, ---- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={1,1,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Setup", click_function="buttonClick_setup", function_owner=self, +--- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={1,1,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Tile Weaver of the Cosmos bbb70a.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Tile Weaver of the Cosmos bbb70a.ttslua index 418a5fce4..5fe6a166c 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Tile Weaver of the Cosmos bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Model_Bag 4-B Weaver of the Cosmos e14c76/Custom_Tile Weaver of the Cosmos bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'Weaver of the Cosmos' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Weaver of the Cosmos' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Tile The Dream-Quest Campaign Log f40183.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Tile The Dream-Quest Campaign Log f40183.ttslua index 28184b1f0..0771ab2f7 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Tile The Dream-Quest Campaign Log f40183.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a16a1a/Custom_Tile The Dream-Quest Campaign Log f40183.ttslua @@ -1,722 +1,722 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {0.902,0.886,0.788} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --1 checkbox - { - pos = {0.306,0.1,0.051}, - size = 250, - state = false - }, - --2 checkbox - { - pos = {0.35,0.1,0.114}, - size = 250, - state = false - }, - --3 checkbox - { - pos = {0.399,0.1,0.169}, - size = 250, - state = false - }, - --4 checkbox - { - pos = {0.455,0.1,0.221}, - size = 250, - state = false - }, - --5 checkbox - { - pos = {0.5,0.1,0.279}, - size = 250, - state = false - }, - --6 checkbox - { - pos = {0.54,0.1,0.334}, - size = 250, - state = false - }, - --7 checkbox - { - pos = {0.568,0.1,0.392}, - size = 250, - state = false - }, - --8 checkbox - { - pos = {0.604,0.1,0.457}, - size = 250, - state = false - }, - --9 checkbox - { - pos = {0.229,0.1,-0.007}, - size = 250, - state = false - }, - --10 checkbox - { - pos = {-0.816,0.1,0.02}, - size = 250, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.50,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.06,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.27}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.27}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.62}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.268}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.62}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.265}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.393,0.1,0.265}, - rows =10, - width = 3200, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Killed Investigators - { - pos = {-0.417,0.1,0.881}, - rows = 4, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Evidence of Kadath - { - pos = {-0.388,0.1,0.676}, - rows = 2, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Chaos Bag - { - pos = {0.782,0.1,0.8}, - rows = 10, - width = 1500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {0.902,0.886,0.788} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --1 checkbox + { + pos = {0.306,0.1,0.051}, + size = 250, + state = false + }, + --2 checkbox + { + pos = {0.35,0.1,0.114}, + size = 250, + state = false + }, + --3 checkbox + { + pos = {0.399,0.1,0.169}, + size = 250, + state = false + }, + --4 checkbox + { + pos = {0.455,0.1,0.221}, + size = 250, + state = false + }, + --5 checkbox + { + pos = {0.5,0.1,0.279}, + size = 250, + state = false + }, + --6 checkbox + { + pos = {0.54,0.1,0.334}, + size = 250, + state = false + }, + --7 checkbox + { + pos = {0.568,0.1,0.392}, + size = 250, + state = false + }, + --8 checkbox + { + pos = {0.604,0.1,0.457}, + size = 250, + state = false + }, + --9 checkbox + { + pos = {0.229,0.1,-0.007}, + size = 250, + state = false + }, + --10 checkbox + { + pos = {-0.816,0.1,0.02}, + size = 250, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.50,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.06,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.27}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.27}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.62}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.268}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.62}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.265}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.393,0.1,0.265}, + rows =10, + width = 3200, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Killed Investigators + { + pos = {-0.417,0.1,0.881}, + rows = 4, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Evidence of Kadath + { + pos = {-0.388,0.1,0.676}, + rows = 2, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Chaos Bag + { + pos = {0.782,0.1,0.8}, + rows = 10, + width = 1500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dream-Eaters a34f34.ttslua b/unpacked/Custom_Model_Bag The Dream-Eaters a34f34.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag The Dream-Eaters a34f34.ttslua +++ b/unpacked/Custom_Model_Bag The Dream-Eaters a34f34.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9/Custom_Tile The Dunwich Legacy f5db25.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9/Custom_Tile The Dunwich Legacy f5db25.ttslua index cfa110e20..39ecc5466 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9/Custom_Tile The Dunwich Legacy f5db25.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1a Extracurricular Activity 51c0d9/Custom_Tile The Dunwich Legacy f5db25.ttslua @@ -1,21 +1,21 @@ -name = 'The Dunwich Legacy' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Dunwich Legacy' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c/Custom_Tile The Dunwich Legacy b5928a.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c/Custom_Tile The Dunwich Legacy b5928a.ttslua index cfa110e20..39ecc5466 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c/Custom_Tile The Dunwich Legacy b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 1b The House Always Wins e3aa5c/Custom_Tile The Dunwich Legacy b5928a.ttslua @@ -1,21 +1,21 @@ -name = 'The Dunwich Legacy' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Dunwich Legacy' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf/Custom_Tile The Miskatonic Museum 703373.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf/Custom_Tile The Miskatonic Museum 703373.ttslua index f92a55f33..ca89f18f6 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf/Custom_Tile The Miskatonic Museum 703373.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 2 The Miskatonic Museum 87adbf/Custom_Tile The Miskatonic Museum 703373.ttslua @@ -1,25 +1,25 @@ -name = 'The Miskatonic Museum' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Miskatonic Museum' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449/Custom_Tile The Essex County Express 247967.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449/Custom_Tile The Essex County Express 247967.ttslua index 8942d6ff8..9ff549176 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449/Custom_Tile The Essex County Express 247967.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 3 The Essex County Express d6e449/Custom_Tile The Essex County Express 247967.ttslua @@ -1,25 +1,25 @@ -name = 'The Essex County Express' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Essex County Express' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d/Custom_Tile Blood on the Altar 92b54a.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d/Custom_Tile Blood on the Altar 92b54a.ttslua index 35359436c..b50b2762f 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d/Custom_Tile Blood on the Altar 92b54a.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 4 Blood on the Altar 30684d/Custom_Tile Blood on the Altar 92b54a.ttslua @@ -1,25 +1,25 @@ -name = 'Blood on the Altar' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Blood on the Altar' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce/Custom_Tile Undimensioned and Unseen 393c71.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce/Custom_Tile Undimensioned and Unseen 393c71.ttslua index 796c0adfa..4da502b94 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce/Custom_Tile Undimensioned and Unseen 393c71.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 5 Undimensioned and Unseen afe7ce/Custom_Tile Undimensioned and Unseen 393c71.ttslua @@ -1,25 +1,25 @@ -name = 'Undimensioned and Unseen' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Undimensioned and Unseen' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf/Custom_Tile Where Doom Awaits a621ae.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf/Custom_Tile Where Doom Awaits a621ae.ttslua index c8658d789..5f3588cb8 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf/Custom_Tile Where Doom Awaits a621ae.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 6 Where Doom Awaits 022ddf/Custom_Tile Where Doom Awaits a621ae.ttslua @@ -1,25 +1,25 @@ -name = 'Where Doom Awaits' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Where Doom Awaits' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060/Custom_Tile Lost in Time and Space 64a607.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060/Custom_Tile Lost in Time and Space 64a607.ttslua index a649f8c03..09337160a 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060/Custom_Tile Lost in Time and Space 64a607.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Model_Bag 7 Lost in Time and Space 684060/Custom_Tile Lost in Time and Space 64a607.ttslua @@ -1,25 +1,25 @@ -name = 'Lost in Time and Space' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Lost in Time and Space' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua index 690a83709..3d43d4f4c 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 2898f6/Custom_Tile Dunwich Legacy Campaign Log 3f6ab6.ttslua @@ -1,669 +1,669 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --First checkbox --- { --- pos = {-0.62,0.1,0.056}, --- size = 400, --- state = false --- }, - --Second checkbox --- { --- pos = {-0.629,0.1,0.199}, --- size = 400, --- state = false --- }, - --Third checkbox --- { --- pos = {-0.594,0.1,0.355}, --- size = 400, --- state = false --- }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.45,0.1,0.55}, - rows =18, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.384,0.1,0.228}, - rows = 8, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Cultists interrogated - { - pos = {0.384,0.1,0.69}, - rows = 8, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --First checkbox +-- { +-- pos = {-0.62,0.1,0.056}, +-- size = 400, +-- state = false +-- }, + --Second checkbox +-- { +-- pos = {-0.629,0.1,0.199}, +-- size = 400, +-- state = false +-- }, + --Third checkbox +-- { +-- pos = {-0.594,0.1,0.355}, +-- size = 400, +-- state = false +-- }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.45,0.1,0.55}, + rows =18, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.384,0.1,0.228}, + rows = 8, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Cultists interrogated + { + pos = {0.384,0.1,0.69}, + rows = 8, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Dunwich Legacy 5889dd.ttslua b/unpacked/Custom_Model_Bag The Dunwich Legacy 5889dd.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag The Dunwich Legacy 5889dd.ttslua +++ b/unpacked/Custom_Model_Bag The Dunwich Legacy 5889dd.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 03b888.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 03b888.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 03b888.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 03b888.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956/Custom_Tile The Forgotten Age e95200.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956/Custom_Tile The Forgotten Age e95200.ttslua index 75c4561fb..200437b6c 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956/Custom_Tile The Forgotten Age e95200.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 1 The Untamed Wilds e90956/Custom_Tile The Forgotten Age e95200.ttslua @@ -1,21 +1,21 @@ -name = 'The Forgotten Age' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Forgotten Age' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1/Custom_Tile The Doom of Eztli 294ec4.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1/Custom_Tile The Doom of Eztli 294ec4.ttslua index 25a046b6a..5672c33bc 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1/Custom_Tile The Doom of Eztli 294ec4.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 2 The Doom of Eztli 065ce1/Custom_Tile The Doom of Eztli 294ec4.ttslua @@ -1,25 +1,25 @@ -name = 'The Doom of Eztli' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Doom of Eztli' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8/Custom_Tile Threads of Fate 7a95f6.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8/Custom_Tile Threads of Fate 7a95f6.ttslua index aa256f497..0d6a8bd42 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8/Custom_Tile Threads of Fate 7a95f6.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 3 Threads of Fate 11f5c8/Custom_Tile Threads of Fate 7a95f6.ttslua @@ -1,25 +1,25 @@ -name = 'Threads of Fate' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Threads of Fate' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f/Custom_Tile The Boundary Beyond 010761.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f/Custom_Tile The Boundary Beyond 010761.ttslua index 88130bf52..f46c523bf 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f/Custom_Tile The Boundary Beyond 010761.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 4 The Boundary Beyond 0ec59f/Custom_Tile The Boundary Beyond 010761.ttslua @@ -1,25 +1,25 @@ -name = 'The Boundary Beyond' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Boundary Beyond' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00/Custom_Tile Heart of the Elders 493cb1.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00/Custom_Tile Heart of the Elders 493cb1.ttslua index 4f3609807..5a7299c73 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00/Custom_Tile Heart of the Elders 493cb1.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 1 2bfe00/Custom_Tile Heart of the Elders 493cb1.ttslua @@ -1,25 +1,25 @@ -name = 'Heart of the Elders' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Heart of the Elders' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 2 5b2403.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 2 5b2403.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 2 5b2403.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 5 Heart of the Elders Part 2 5b2403.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce/Custom_Tile The City of Archives 2fb6dc.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce/Custom_Tile The City of Archives 2fb6dc.ttslua index 787f8705f..3224092d4 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce/Custom_Tile The City of Archives 2fb6dc.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 6 The City of Archives 3170ce/Custom_Tile The City of Archives 2fb6dc.ttslua @@ -1,25 +1,25 @@ -name = 'The City of Archives' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The City of Archives' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Tile The Depths of Yoth 7aa4e3.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Tile The Depths of Yoth 7aa4e3.ttslua index 7d9affdc4..e569e19b2 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Tile The Depths of Yoth 7aa4e3.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Tile The Depths of Yoth 7aa4e3.ttslua @@ -1,25 +1,25 @@ -name = 'The Depths of Yoth' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Depths of Yoth' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - EasyStandard dd61f1.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - EasyStandard dd61f1.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - EasyStandard dd61f1.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - EasyStandard dd61f1.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - HardExpert 2da146.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - HardExpert 2da146.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - HardExpert 2da146.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 7 The Depths of Yoth 85286a/Custom_Token Scenario - HardExpert 2da146.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d/Custom_Tile Shattered Aeons 6dc72a.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d/Custom_Tile Shattered Aeons 6dc72a.ttslua index b78ce3eb4..b31a42434 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d/Custom_Tile Shattered Aeons 6dc72a.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 8 Shattered Aeons 737c5d/Custom_Tile Shattered Aeons 6dc72a.ttslua @@ -1,21 +1,21 @@ -name = 'Shattered Aeons' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Shattered Aeons' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 9 Secret Scenario c52079.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 9 Secret Scenario c52079.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 9 Secret Scenario c52079.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Model_Bag 9 Secret Scenario c52079.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua index 3e3ff898f..682c9d34c 100644 --- a/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua +++ b/unpacked/Custom_Model_Bag The Forgotten Age 0bcf19/Custom_Tile Forgotten Age Campaign Log 48b154.ttslua @@ -1,691 +1,691 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Yig's Fury - { - pos = {0.097,0.1,0.88}, - size = 500, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one Supplies - { - pos = {-0.637,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two supplies - { - pos = {-0.2,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three supplies - { - pos = {0.24,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.25}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four supplies - { - pos = {0.671,0.1,0.05}, - rows = 7, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.475,0.1,0.62}, - rows =12, - width = 3200, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.527,0.1,0.507}, - rows = 12, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Yig's Fury + { + pos = {0.097,0.1,0.88}, + size = 500, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one Supplies + { + pos = {-0.637,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two supplies + { + pos = {-0.2,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three supplies + { + pos = {0.24,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.25}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four supplies + { + pos = {0.671,0.1,0.05}, + rows = 7, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.475,0.1,0.62}, + rows =12, + width = 3200, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.527,0.1,0.507}, + rows = 12, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 10bd18.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 10bd18.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 10bd18.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 10bd18.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838/Custom_Tile The Innsmouth Conspiracy 16562e.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838/Custom_Tile The Innsmouth Conspiracy 16562e.ttslua index f8bd0074b..1f1e08361 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838/Custom_Tile The Innsmouth Conspiracy 16562e.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 1 The Pit of Despair c09838/Custom_Tile The Innsmouth Conspiracy 16562e.ttslua @@ -1,21 +1,21 @@ -name = 'The Innsmouth Conspiracy' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Innsmouth Conspiracy' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 2 The Vanishing of Elina Harper 8c6d05.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 2 The Vanishing of Elina Harper 8c6d05.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 2 The Vanishing of Elina Harper 8c6d05.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 2 The Vanishing of Elina Harper 8c6d05.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225/Custom_Tile In Too Deep bbb70a.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225/Custom_Tile In Too Deep bbb70a.ttslua index 74f4e72ef..6da01d7cc 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225/Custom_Tile In Too Deep bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Model_Bag 3 In Too Deep c3a225/Custom_Tile In Too Deep bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'In Too Deep' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'In Too Deep' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Tile The Innsmouth Conspiracy Campaign Log f40183.ttslua b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Tile The Innsmouth Conspiracy Campaign Log f40183.ttslua index 63966807b..2d9e70e3f 100644 --- a/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Tile The Innsmouth Conspiracy Campaign Log f40183.ttslua +++ b/unpacked/Custom_Model_Bag The Innsmouth Conspiracy 465aab/Custom_Tile The Innsmouth Conspiracy Campaign Log f40183.ttslua @@ -1,669 +1,669 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {0.902,0.886,0.788} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --1 checkbox --- { --- pos = {0.306,0.1,0.05}, --- size = 250, --- state = false --- }, - - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.46}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.51,0.1,-0.46}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.56}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.455}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.06,0.1,-0.455}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.15,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.64,0.1,-0.72}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.64,0.1,-0.63}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.64,0.1,-0.27}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.715}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.63}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.27}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.71}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.24,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.268}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.69,0.1,-0.71}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.69,0.1,-0.62}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.265}, - rows = 9, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Memories Recovered - { - pos = {0.44,0.1,0.325}, - rows =14, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.43,0.1,0.33}, - rows =14, - width = 3500, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {-0.478,0.1,0.8}, - rows = 8, - width = 3000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Killed and Insane - { - pos = {0.448,0.1,0.887}, - rows = 5, - width = 4000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {0.902,0.886,0.788} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --1 checkbox +-- { +-- pos = {0.306,0.1,0.05}, +-- size = 250, +-- state = false +-- }, + + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.46}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.51,0.1,-0.46}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.56}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.455}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.06,0.1,-0.455}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.15,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.64,0.1,-0.72}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.64,0.1,-0.63}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.64,0.1,-0.27}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.715}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.63}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.27}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.71}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.24,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.268}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.69,0.1,-0.71}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.69,0.1,-0.62}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.265}, + rows = 9, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Memories Recovered + { + pos = {0.44,0.1,0.325}, + rows =14, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.43,0.1,0.33}, + rows =14, + width = 3500, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {-0.478,0.1,0.8}, + rows = 8, + width = 3000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Killed and Insane + { + pos = {0.448,0.1,0.887}, + rows = 5, + width = 4000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa 899c3a.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa 899c3a.ttslua index daed6bf90..4798d294b 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa 899c3a.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa 899c3a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, - font_size=700, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.4,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.4,3,-8.4}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.4,3,-7.2}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-2.4,3,7}, rotation={0,0,0}, height=850, width=2000, + font_size=700, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua index 978a9d2b5..7878134ac 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 1 Curtain Call 83ccd4/Custom_Tile The Path to Carcosa 16562e.ttslua @@ -1,21 +1,21 @@ -name = 'The Path to Carcosa' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Path to Carcosa' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua index c9acd00d0..80ce317d3 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 2 The Last King 6730a1/Custom_Tile The Last King 857d0d.ttslua @@ -1,25 +1,25 @@ -name = 'The Last King' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Last King' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua index 9852aeb27..fd833106f 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 3 Echoes of the Past 42d2dc/Custom_Tile Echoes of the Past 452210.ttslua @@ -1,25 +1,25 @@ -name = 'Echoes of the Past' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Echoes of the Past' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua index f7109dddb..e78b2e78a 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 4 The Unspeakable Oath e7efa6/Custom_Tile The Unspeakable Oath 87f45e.ttslua @@ -1,25 +1,25 @@ -name = 'The Unspeakable Oath' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Unspeakable Oath' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua index e092a5769..bacd5051f 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 5 A Phantom of Truth bd4167/Custom_Tile A Phantom of Truth b20b8d.ttslua @@ -1,25 +1,25 @@ -name = 'A Phantom of Truth' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'A Phantom of Truth' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua index 9607689ac..c36627e17 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 6 The Pallid Mask eb48ff/Custom_Tile The Pallid Mask bb070d.ttslua @@ -1,25 +1,25 @@ -name = 'The Pallid Mask' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Pallid Mask' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag b29b71.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Bag Setup Randomizer 7c8232/Bag Setup Bag d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua index 78350373e..a505ccca6 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 7 Black Stars Rise dd8b0d/Custom_Tile Black Stars Rise 20c21d.ttslua @@ -1,25 +1,25 @@ -name = 'Black Stars Rise' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Black Stars Rise' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua index 710b4a84e..ffa409a5f 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Model_Bag 8 Dim Carcosa ce5d30/Custom_Tile Dim Carcosa 9afdfd.ttslua @@ -1,25 +1,25 @@ -name = 'Dim Carcosa' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Dim Carcosa' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Tile Carcosa Campaign Log ae8317.ttslua b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Tile Carcosa Campaign Log ae8317.ttslua index 108024431..7a861eb36 100644 --- a/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Tile Carcosa Campaign Log ae8317.ttslua +++ b/unpacked/Custom_Model_Bag The Path to Carcosa aca04c/Custom_Tile Carcosa Campaign Log ae8317.ttslua @@ -1,755 +1,755 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --Doubt 1 - { - pos = {-0.482,0.1,0.776}, - size = 200, - state = false - }, - --Doubt 2 - { - pos = {-0.43,0.1,0.776}, - size = 200, - state = false - }, - --Doubt 3 - { - pos = {-0.38,0.1,0.775}, - size = 200, - state = false - }, - --Doubt 4 - { - pos = {-0.325,0.1,0.778}, - size = 200, - state = false - }, - --Doubt 5 - { - pos = {-0.27,0.1,0.779}, - size = 200, - state = false - }, - --Doubt 6 - { - pos = {-0.219,0.1,0.778}, - size = 200, - state = false - }, - --Doubt 7 - { - pos = {-0.168,0.1,0.782}, - size = 200, - state = false - }, - --Doubt 8 - { - pos = {-0.111,0.1,0.783}, - size = 200, - state = false - }, - --Conviction 1 - { - pos = {-0.736,0.1,0.868}, - size = 200, - state = false - }, - --Conviction 2 - { - pos = {-0.68,0.1,0.869}, - size = 200, - state = false - }, - --Conviction 3 - { - pos = {-0.626,0.1,0.869}, - size = 200, - state = false - }, - --Conviction 4 - { - pos = {-0.574,0.1,0.874}, - size = 200, - state = false - }, - --Conviction 5 - { - pos = {-0.519,0.1,0.874}, - size = 200, - state = false - }, - --Conviction 6 - { - pos = {-0.467,0.1,0.879}, - size = 200, - state = false - }, - --Conviction 7 - { - pos = {-0.416,0.1,0.876}, - size = 200, - state = false - }, - --Conviction 8 - { - pos = {-0.357,0.1,0.879}, - size = 200, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.7,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.52,0.1,-0.45}, - size = 400, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.517,0.1,-0.55}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.274,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.074,0.1,-0.445}, - size = 400, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.061,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {0.153,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {0.379,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {0.38,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {0.614,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {0.82,0.1,-0.44}, - size = 400, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {0.827,0.1,-0.54}, - size = 300, - value = 0, - hideBG = true - }, - --Chasing The Stranger - { - pos = {0.414,0.1,0.106}, - size = 500, - value = 0, - hideBG = true - }, - - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.637,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.637,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.637,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.2,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.2,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.2,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {0.241,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {0.237,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {0.24,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {0.671,0.1,-0.70}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {0.671,0.1,-0.625}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {0.671,0.1,-0.32}, - rows = 5, - width = 2000, - font_size = 100, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.38,0.1,0.339}, - rows =16, - width = 3200, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --VIPs Interviewed - { - pos = {0.43,0.1,0.338}, - rows = 6, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --VIPs Slain - { - pos = {0.43,0.1,0.643}, - rows = 6, - width = 3500, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --Doubt 1 + { + pos = {-0.482,0.1,0.776}, + size = 200, + state = false + }, + --Doubt 2 + { + pos = {-0.43,0.1,0.776}, + size = 200, + state = false + }, + --Doubt 3 + { + pos = {-0.38,0.1,0.775}, + size = 200, + state = false + }, + --Doubt 4 + { + pos = {-0.325,0.1,0.778}, + size = 200, + state = false + }, + --Doubt 5 + { + pos = {-0.27,0.1,0.779}, + size = 200, + state = false + }, + --Doubt 6 + { + pos = {-0.219,0.1,0.778}, + size = 200, + state = false + }, + --Doubt 7 + { + pos = {-0.168,0.1,0.782}, + size = 200, + state = false + }, + --Doubt 8 + { + pos = {-0.111,0.1,0.783}, + size = 200, + state = false + }, + --Conviction 1 + { + pos = {-0.736,0.1,0.868}, + size = 200, + state = false + }, + --Conviction 2 + { + pos = {-0.68,0.1,0.869}, + size = 200, + state = false + }, + --Conviction 3 + { + pos = {-0.626,0.1,0.869}, + size = 200, + state = false + }, + --Conviction 4 + { + pos = {-0.574,0.1,0.874}, + size = 200, + state = false + }, + --Conviction 5 + { + pos = {-0.519,0.1,0.874}, + size = 200, + state = false + }, + --Conviction 6 + { + pos = {-0.467,0.1,0.879}, + size = 200, + state = false + }, + --Conviction 7 + { + pos = {-0.416,0.1,0.876}, + size = 200, + state = false + }, + --Conviction 8 + { + pos = {-0.357,0.1,0.879}, + size = 200, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.7,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.52,0.1,-0.45}, + size = 400, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.517,0.1,-0.55}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.274,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.074,0.1,-0.445}, + size = 400, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.061,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {0.153,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {0.379,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {0.38,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {0.614,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {0.82,0.1,-0.44}, + size = 400, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {0.827,0.1,-0.54}, + size = 300, + value = 0, + hideBG = true + }, + --Chasing The Stranger + { + pos = {0.414,0.1,0.106}, + size = 500, + value = 0, + hideBG = true + }, + + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.637,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.637,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.637,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.2,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.2,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.2,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {0.241,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {0.237,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {0.24,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {0.671,0.1,-0.70}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {0.671,0.1,-0.625}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {0.671,0.1,-0.32}, + rows = 5, + width = 2000, + font_size = 100, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.38,0.1,0.339}, + rows =16, + width = 3200, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --VIPs Interviewed + { + pos = {0.43,0.1,0.338}, + rows = 6, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --VIPs Slain + { + pos = {0.43,0.1,0.643}, + rows = 6, + width = 3500, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1.ttslua index beb7e9fed..c99612b1a 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 4 - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, - font_size=350, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 4 + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1.25,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1.25,0.3,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1.25,0.3,-7}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1.25,0.3,-8}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1.35,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1.25,1,6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-6}, rotation={0,0,0}, height=500, width=1200, + font_size=350, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0/Custom_Tile Against the Wendigo 82e1ed.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0/Custom_Tile Against the Wendigo 82e1ed.ttslua index d47035472..bd968c218 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0/Custom_Tile Against the Wendigo 82e1ed.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Against the Wendigo 4d5fa0/Custom_Tile Against the Wendigo 82e1ed.ttslua @@ -1,21 +1,21 @@ -name = 'Bread and Circuses' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Bread and Circuses' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 1 Arkham in Wonderland 18aa54.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 1 Arkham in Wonderland 18aa54.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 1 Arkham in Wonderland 18aa54.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 1 Arkham in Wonderland 18aa54.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-A A Sea of Troubles 952572.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-A A Sea of Troubles 952572.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-A A Sea of Troubles 952572.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-A A Sea of Troubles 952572.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-B Tempest in a Teapot 8d88c8.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-B Tempest in a Teapot 8d88c8.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-B Tempest in a Teapot 8d88c8.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-B Tempest in a Teapot 8d88c8.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-C Bleeding Hearts 8eb793.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-C Bleeding Hearts 8eb793.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-C Bleeding Hearts 8eb793.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-C Bleeding Hearts 8eb793.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-D Wild Snark Chase 9e33a0.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-D Wild Snark Chase 9e33a0.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-D Wild Snark Chase 9e33a0.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-D Wild Snark Chase 9e33a0.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-E Sibling Rivalry 0916b6.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-E Sibling Rivalry 0916b6.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-E Sibling Rivalry 0916b6.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-E Sibling Rivalry 0916b6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-F Fool's Mate bd556e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-F Fool's Mate bd556e.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-F Fool's Mate bd556e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 2-F Fool's Mate bd556e.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 3 Lucid Nightmare e6bb63.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 3 Lucid Nightmare e6bb63.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 3 Lucid Nightmare e6bb63.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Model_Bag 3 Lucid Nightmare e6bb63.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Tile Alice in Wonderland b5928a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Tile Alice in Wonderland b5928a.ttslua index db124ee3b..210076a48 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Tile Alice in Wonderland b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Tile Alice in Wonderland b5928a.ttslua @@ -1,21 +1,21 @@ -name = 'Alice in Wonderland' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Alice in Wonderland' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Token Alice in Wonderland Campaign Log eda22b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Token Alice in Wonderland Campaign Log eda22b.ttslua index 6b9789fb2..b42812626 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Token Alice in Wonderland Campaign Log eda22b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Alice in Wonderland 39916d/Custom_Token Alice in Wonderland Campaign Log eda22b.ttslua @@ -1,651 +1,651 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --1st Player Experience - { - pos = {-1.080,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --1st Player Physical Trauma - { - pos = {-1.270,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --1st Player Mental Trauma - { - pos = {-1.000,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Experience - { - pos = {-0.251,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --2nd Player Physical Trauma - { - pos = {-0.441,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Mental Trauma - { - pos = {-0.171,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Experience - { - pos = {0.579,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --3rd Player Physical Trauma - { - pos = {0.389,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Mental Trauma - { - pos = {0.659,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Experience - { - pos = {1.407,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --4th Player Physical Trauma - { - pos = {1.217,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Mental Trauma - { - pos = {1.487,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --1st Player Name - { - pos = {-1.265,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Investigator - { - pos = {-1.265,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Story Assets/Weaknesses - { - pos = {-1.265,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Name - { - pos = {-0.436,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Investigator - { - pos = {-0.436,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Story Assets/Weaknesses - { - pos = {-0.436,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Name - { - pos = {0.394,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Investigator - { - pos = {0.394,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Story Assets/Weaknesses - { - pos = {0.394,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Name - { - pos = {1.222,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Investigator - { - pos = {1.222,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Story Assets/Weaknesses - { - pos = {1.222,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.930,0.1,0.990}, - rows = 25, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.820,0.1,0.707}, - rows = 20, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Killed and Insane Investigators - { - pos = {1.010,0.1,1.700}, - rows = 5, - width = 7400, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --1st Player Experience + { + pos = {-1.080,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --1st Player Physical Trauma + { + pos = {-1.270,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --1st Player Mental Trauma + { + pos = {-1.000,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Experience + { + pos = {-0.251,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --2nd Player Physical Trauma + { + pos = {-0.441,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Mental Trauma + { + pos = {-0.171,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Experience + { + pos = {0.579,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --3rd Player Physical Trauma + { + pos = {0.389,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Mental Trauma + { + pos = {0.659,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Experience + { + pos = {1.407,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --4th Player Physical Trauma + { + pos = {1.217,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Mental Trauma + { + pos = {1.487,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --1st Player Name + { + pos = {-1.265,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Investigator + { + pos = {-1.265,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Story Assets/Weaknesses + { + pos = {-1.265,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Name + { + pos = {-0.436,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Investigator + { + pos = {-0.436,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Story Assets/Weaknesses + { + pos = {-0.436,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Name + { + pos = {0.394,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Investigator + { + pos = {0.394,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Story Assets/Weaknesses + { + pos = {0.394,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Name + { + pos = {1.222,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Investigator + { + pos = {1.222,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Story Assets/Weaknesses + { + pos = {1.222,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.930,0.1,0.990}, + rows = 25, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.820,0.1,0.707}, + rows = 20, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Killed and Insane Investigators + { + pos = {1.010,0.1,1.700}, + rows = 5, + width = 7400, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag With Return Set 083fc2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag With Return Set 083fc2.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag With Return Set 083fc2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag With Return Set 083fc2.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag Without Return Set d14543.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag Without Return Set d14543.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag Without Return Set d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Bag Without Return Set d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Custom_Tile All or Nothing b5928a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Custom_Tile All or Nothing b5928a.ttslua index b3e5ec0ed..bc17232b9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Custom_Tile All or Nothing b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag All or Nothing 72ab92/Custom_Tile All or Nothing b5928a.ttslua @@ -1,21 +1,21 @@ -name = 'All or Nothing' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'All or Nothing' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da/Custom_Tile Blood Spilled in Salem 83b781.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da/Custom_Tile Blood Spilled in Salem 83b781.ttslua index 019f2aa3f..438f92e12 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da/Custom_Tile Blood Spilled in Salem 83b781.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Blood Spilled in Salem 4237da/Custom_Tile Blood Spilled in Salem 83b781.ttslua @@ -1,21 +1,21 @@ -name = 'Blood Spilled in Salem' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Blood Spilled in Salem' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97/Custom_Tile Bridge of Sighs 2d9794.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97/Custom_Tile Bridge of Sighs 2d9794.ttslua index aa4315356..0eecb494e 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97/Custom_Tile Bridge of Sighs 2d9794.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Bridge of Sighs 578e97/Custom_Tile Bridge of Sighs 2d9794.ttslua @@ -1,21 +1,21 @@ -name = 'Bridge of Sighs' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Bridge of Sighs' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51/Custom_Tile Carnevale of Horrors a5891b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51/Custom_Tile Carnevale of Horrors a5891b.ttslua index 6b3e44012..78c608dc2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51/Custom_Tile Carnevale of Horrors a5891b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Horrors 23dd51/Custom_Tile Carnevale of Horrors a5891b.ttslua @@ -1,13 +1,13 @@ -name = 'Carnevale of Horrors' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end +name = 'Carnevale of Horrors' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Model_Bag Set-aside a45247/Bag Atlach-Nacha d14543.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Model_Bag Set-aside a45247/Bag Atlach-Nacha d14543.ttslua index 4d4017455..512f2eed0 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Model_Bag Set-aside a45247/Bag Atlach-Nacha d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Model_Bag Set-aside a45247/Bag Atlach-Nacha d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Tile Carnevale of Spiders a5891b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Tile Carnevale of Spiders a5891b.ttslua index 6b3e44012..78c608dc2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Tile Carnevale of Spiders a5891b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Carnevale of Spiders e57017/Custom_Tile Carnevale of Spiders a5891b.ttslua @@ -1,13 +1,13 @@ -name = 'Carnevale of Horrors' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end +name = 'Carnevale of Horrors' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Bag Additional locations d14543.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Bag Additional locations d14543.ttslua index f82d90245..758efa0e2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Bag Additional locations d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Bag Additional locations d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Setup", click_function="buttonClick_setup", function_owner=self, ---- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={1,1,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Setup", click_function="buttonClick_setup", function_owner=self, +--- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={1,1,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Custom_Tile Consternation on the Constellation bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Custom_Tile Consternation on the Constellation bbb70a.ttslua index 9732c81e8..1b866fa18 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Custom_Tile Consternation on the Constellation bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Consternation on the Constellation 0ec730/Custom_Tile Consternation on the Constellation bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'Consternation' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Consternation' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Bag Locations 73e53d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Bag Locations 73e53d.ttslua index 1cfc46617..be2fd274b 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Bag Locations 73e53d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Bag Locations 73e53d.ttslua @@ -1,5 +1,5 @@ -function onCollisionEnter(collision_info) - self.shuffle() - self.shuffle() - self.shuffle() -end +function onCollisionEnter(collision_info) + self.shuffle() + self.shuffle() + self.shuffle() +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Custom_Tile Curse of the Rougarou cf0c00.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Custom_Tile Curse of the Rougarou cf0c00.ttslua index 8c433dcd4..682e30022 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Custom_Tile Curse of the Rougarou cf0c00.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Curse of the Rougarou db7039/Custom_Tile Curse of the Rougarou cf0c00.ttslua @@ -1,13 +1,13 @@ -name = 'Curse of the Rougarou' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end +name = 'Curse of the Rougarou' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model Dark Matter Custom Data Helper a57738.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model Dark Matter Custom Data Helper a57738.ttslua index eb4a0b421..d42a554fe 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model Dark Matter Custom Data Helper a57738.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model Dark Matter Custom Data Helper a57738.ttslua @@ -1,83 +1,83 @@ --- set true to enable debug logging -DEBUG = false - -function log(message) - if DEBUG then - print(message) - end -end - ---[[ -Known locations and clues. We check this to determine if we should -atttempt to spawn clues, first we look for _ and if -we find nothing we look for -format is [location_guid -> clueCount] -]] -LOCATIONS_DATA_JSON = [[ -{ - "Cargo Hold": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Cryosleep Quarters": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Engine Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Escape Pod Bay": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Infirmary": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Mess Hall": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Ship's Bridge": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Ventilation Shaft": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Cafeteria": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Classroom K2": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Entrance Hall": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Gymnasium": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Biology Lab": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Library": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "School Grounds": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "Cold Wastes": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Crystal Peak": {"type": "perPlayer", "value": 3, "clueSide": "front"}, - "Ice Spires": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Main Facility": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Omni-Transmitters": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Q-Crystal Mines": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "Airlocks": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Crew Quarters": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Flight Deck": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Hydroponics": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Infirmary_N": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Ship Mainframe": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Telecoms": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "A Hiding Place": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "A Mutiny": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Adrift in Space": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "An Accident": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "City of Cats": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Fever Dream": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "Abandoned Lander": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Cyclopean Caverns": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Garden of Delights": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Grand Ballroom": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Spiral Staircase": {"type": "fixed", "value": 1, "clueSide": "back"}, - "The Yellow Throne": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Whisper Labyrinth": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "New Brooklyn": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Hope": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Yuggoth": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Mount Sinai": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Derelict Ship": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Martian Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Olympus Telescope": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Moonbase Laboratory": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Threshold of Yuggoth": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Earth": {"type": "perPlayer", "value": 2, "clueSide": "front"} -} -]] - -LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) - -function onload(save_state) - local playArea = getObjectFromGUID('721ba2') - playArea.call("updateLocations", {self.getGUID()}) -end +-- set true to enable debug logging +DEBUG = false + +function log(message) + if DEBUG then + print(message) + end +end + +--[[ +Known locations and clues. We check this to determine if we should +atttempt to spawn clues, first we look for _ and if +we find nothing we look for +format is [location_guid -> clueCount] +]] +LOCATIONS_DATA_JSON = [[ +{ + "Cargo Hold": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Cryosleep Quarters": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Engine Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Escape Pod Bay": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Infirmary": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Mess Hall": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Ship's Bridge": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Ventilation Shaft": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Cafeteria": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Classroom K2": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Entrance Hall": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Gymnasium": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Biology Lab": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Library": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "School Grounds": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "Cold Wastes": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Crystal Peak": {"type": "perPlayer", "value": 3, "clueSide": "front"}, + "Ice Spires": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Main Facility": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Omni-Transmitters": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Q-Crystal Mines": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "Airlocks": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Crew Quarters": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Flight Deck": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Hydroponics": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Infirmary_N": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Ship Mainframe": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Telecoms": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "A Hiding Place": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "A Mutiny": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Adrift in Space": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "An Accident": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "City of Cats": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Fever Dream": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "Abandoned Lander": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Cyclopean Caverns": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Garden of Delights": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Grand Ballroom": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Spiral Staircase": {"type": "fixed", "value": 1, "clueSide": "back"}, + "The Yellow Throne": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Whisper Labyrinth": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "New Brooklyn": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Hope": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Yuggoth": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Mount Sinai": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Derelict Ship": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Martian Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Olympus Telescope": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Moonbase Laboratory": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Threshold of Yuggoth": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Earth": {"type": "perPlayer", "value": 2, "clueSide": "front"} +} +]] + +LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) + +function onload(save_state) + local playArea = getObjectFromGUID('721ba2') + playArea.call("updateLocations", {self.getGUID()}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Electric Nightmare 2bd90b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Electric Nightmare 2bd90b.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Electric Nightmare 2bd90b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Electric Nightmare 2bd90b.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Fragment of Carcosa a492bc.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Fragment of Carcosa a492bc.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Fragment of Carcosa a492bc.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Fragment of Carcosa a492bc.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag In the Shadow of Earth 8cfe99.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag In the Shadow of Earth 8cfe99.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag In the Shadow of Earth 8cfe99.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag In the Shadow of Earth 8cfe99.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Lost Quantum c29a78.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Lost Quantum c29a78.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Lost Quantum c29a78.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Lost Quantum c29a78.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Starfall e04c21.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Starfall e04c21.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Starfall e04c21.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Starfall e04c21.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Strange Moons 2ebcda.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Strange Moons 2ebcda.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Strange Moons 2ebcda.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag Strange Moons 2ebcda.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Machine in Yellow 32039e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Machine in Yellow 32039e.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Machine in Yellow 32039e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Machine in Yellow 32039e.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Tatteremalion 51fbbc.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Tatteremalion 51fbbc.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Tatteremalion 51fbbc.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Model_Bag The Tatteremalion 51fbbc.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile 0aa185.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile 0aa185.ttslua index 2d033f3ff..73d04e8c1 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile 0aa185.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile 0aa185.ttslua @@ -1,736 +1,736 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --First checkbox - { - pos = {0.54,0.11,0.02}, - size = 200, - state = false - }, - --Second checkbox - { - pos = {0.545,0.11,0.07}, - size = 200, - state = false - }, - --Third checkbox - { - pos = {0.553,0.11,0.14}, - size = 200, - state = false - }, - -- Fourth Checkbox - { - pos = {0.505,0.11,0.27}, - size = 200, - state = false - }, - -- Fifth Checkbox - { - pos = {0.715,0.11,0.3}, - size = 200, - state = false - }, - -- Sixth Checkbox - { - pos = {0.54,0.11,0.37}, - size = 200, - state = false - }, - -- Seventh Checkbox - { - pos = {0.575,0.11,0.45}, - size = 200, - state = false - }, - -- Eigth Checkbox - { - pos = {0.675,0.11,0.515}, - size = 200, - state = false - }, - -- Ninth Checkbox - { - pos = {0.64,0.11,0.565}, - size = 200, - state = false - }, - -- Tenth Checkbox - { - pos = {0.428,0.11,0.637}, - size = 200, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --Slot one counter 1 - { - pos = {-0.615,0.11,-0.42}, - size = 300, - value = 0, - hideBG = true - }, - --Slot one counter 2 - { - pos = {-0.47,0.11,-0.42}, - size = 300, - value = 0, - hideBG = true - }, - --Slot one xp 1 - { - pos = {-0.47,0.11,-0.51}, - size = 300, - value = 0, - hideBG = true - }, - --Slot one Memories - { - pos = {-0.615,0.11,-0.335}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 1 - { - pos = {-0.19,0.11,-0.42}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two counter 2 - { - pos = {-0.045,0.11,-0.42}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two xp 1 - { - pos = {-0.045,0.11,-0.51}, - size = 300, - value = 0, - hideBG = true - }, - --Slot two Memories - { - pos = {-0.19,0.11,-0.335}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 1 - { - pos = {-0.615,0.11,0.132}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three counter 2 - { - pos = {-0.47,0.11,0.132}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three xp 1 - { - pos = {-0.47,0.11,0.042}, - size = 300, - value = 0, - hideBG = true - }, - --Slot three Memories - { - pos = {-0.615,0.11,0.217}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 1 - { - pos = {-0.19,0.11,0.132}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four counter 2 - { - pos = {-0.045,0.11,0.132}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four xp 1 - { - pos = {-0.045,0.11,0.042}, - size = 300, - value = 0, - hideBG = true - }, - --Slot four Memories - { - pos = {-0.74,0.11,0.75}, - size = 600, - value = 0, - hideBG = true - }, - --Impending Doom - { - pos = {-0.19,0.11,0.217}, - size = 300, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --Slot one player - { - pos = {-0.615,0.11,-0.635}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one investigator - { - pos = {-0.615,0.11,-0.57}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot one story - { - pos = {-0.615,0.11,-0.21}, - rows = 4, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two player - { - pos = {-0.19,0.11,-0.635}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two investigator - { - pos = {-0.19,0.11,-0.57}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot two story - { - pos = {-0.19,0.1,-0.21}, - rows = 4, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three player - { - pos = {-0.615,0.11,-0.083}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three investigator - { - pos = {-0.615,0.11,-0.017}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot three story - { - pos = {-0.615,0.11,0.34}, - rows = 4, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four player - { - pos = {-0.19,0.11,-0.083}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four investigator - { - pos = {-0.19,0.11,-0.017}, - rows = 1, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Slot four story - { - pos = {-0.19,0.11,0.34}, - rows = 4, - width = 2000, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --Killed Textbox - { - pos = {0.46,0.11,0.85}, - rows = 2, - width = 3000, - font_size = 200, - label = "Click to type", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {0.44,0.11,-0.44}, - rows = 18, - width = 3200, - font_size = 150, - label = "Click to type", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --First checkbox + { + pos = {0.54,0.11,0.02}, + size = 200, + state = false + }, + --Second checkbox + { + pos = {0.545,0.11,0.07}, + size = 200, + state = false + }, + --Third checkbox + { + pos = {0.553,0.11,0.14}, + size = 200, + state = false + }, + -- Fourth Checkbox + { + pos = {0.505,0.11,0.27}, + size = 200, + state = false + }, + -- Fifth Checkbox + { + pos = {0.715,0.11,0.3}, + size = 200, + state = false + }, + -- Sixth Checkbox + { + pos = {0.54,0.11,0.37}, + size = 200, + state = false + }, + -- Seventh Checkbox + { + pos = {0.575,0.11,0.45}, + size = 200, + state = false + }, + -- Eigth Checkbox + { + pos = {0.675,0.11,0.515}, + size = 200, + state = false + }, + -- Ninth Checkbox + { + pos = {0.64,0.11,0.565}, + size = 200, + state = false + }, + -- Tenth Checkbox + { + pos = {0.428,0.11,0.637}, + size = 200, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --Slot one counter 1 + { + pos = {-0.615,0.11,-0.42}, + size = 300, + value = 0, + hideBG = true + }, + --Slot one counter 2 + { + pos = {-0.47,0.11,-0.42}, + size = 300, + value = 0, + hideBG = true + }, + --Slot one xp 1 + { + pos = {-0.47,0.11,-0.51}, + size = 300, + value = 0, + hideBG = true + }, + --Slot one Memories + { + pos = {-0.615,0.11,-0.335}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 1 + { + pos = {-0.19,0.11,-0.42}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two counter 2 + { + pos = {-0.045,0.11,-0.42}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two xp 1 + { + pos = {-0.045,0.11,-0.51}, + size = 300, + value = 0, + hideBG = true + }, + --Slot two Memories + { + pos = {-0.19,0.11,-0.335}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 1 + { + pos = {-0.615,0.11,0.132}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three counter 2 + { + pos = {-0.47,0.11,0.132}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three xp 1 + { + pos = {-0.47,0.11,0.042}, + size = 300, + value = 0, + hideBG = true + }, + --Slot three Memories + { + pos = {-0.615,0.11,0.217}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 1 + { + pos = {-0.19,0.11,0.132}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four counter 2 + { + pos = {-0.045,0.11,0.132}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four xp 1 + { + pos = {-0.045,0.11,0.042}, + size = 300, + value = 0, + hideBG = true + }, + --Slot four Memories + { + pos = {-0.74,0.11,0.75}, + size = 600, + value = 0, + hideBG = true + }, + --Impending Doom + { + pos = {-0.19,0.11,0.217}, + size = 300, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --Slot one player + { + pos = {-0.615,0.11,-0.635}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one investigator + { + pos = {-0.615,0.11,-0.57}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot one story + { + pos = {-0.615,0.11,-0.21}, + rows = 4, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two player + { + pos = {-0.19,0.11,-0.635}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two investigator + { + pos = {-0.19,0.11,-0.57}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot two story + { + pos = {-0.19,0.1,-0.21}, + rows = 4, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three player + { + pos = {-0.615,0.11,-0.083}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three investigator + { + pos = {-0.615,0.11,-0.017}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot three story + { + pos = {-0.615,0.11,0.34}, + rows = 4, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four player + { + pos = {-0.19,0.11,-0.083}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four investigator + { + pos = {-0.19,0.11,-0.017}, + rows = 1, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Slot four story + { + pos = {-0.19,0.11,0.34}, + rows = 4, + width = 2000, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --Killed Textbox + { + pos = {0.46,0.11,0.85}, + rows = 2, + width = 3000, + font_size = 200, + label = "Click to type", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {0.44,0.11,-0.44}, + rows = 18, + width = 3200, + font_size = 150, + label = "Click to type", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile Dark Matter b5928a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile Dark Matter b5928a.ttslua index 1f739f097..cb99e61bb 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile Dark Matter b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Tile Dark Matter b5928a.ttslua @@ -1,21 +1,21 @@ -name = 'Dark Matter' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Dark Matter' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 13bc7d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 13bc7d.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 13bc7d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 13bc7d.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 66dad0.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 66dad0.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 66dad0.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 66dad0.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 794376.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 794376.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 794376.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 794376.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 99db87.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 99db87.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 99db87.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Dark Matter 7458b7/Custom_Token Memories 99db87.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612/Custom_Tile Darkness Falls b5928a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612/Custom_Tile Darkness Falls b5928a.ttslua index 67ad5da9e..c8c78d011 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612/Custom_Tile Darkness Falls b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Darkness Falls c6a612/Custom_Tile Darkness Falls b5928a.ttslua @@ -1,21 +1,21 @@ -name = 'Darkness Falls' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Darkness Falls' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e.ttslua index 2644aff3f..4cd89ff71 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e/Custom_Tile Delta Geen Convergence 520889.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e/Custom_Tile Delta Geen Convergence 520889.ttslua index 77ec0033d..c97f5a60c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e/Custom_Tile Delta Geen Convergence 520889.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Delta Green Convergence ac164e/Custom_Tile Delta Geen Convergence 520889.ttslua @@ -1,21 +1,21 @@ -name = 'Delta Green' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Delta Green' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Dead by Dawn c29a78.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Dead by Dawn c29a78.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Dead by Dawn c29a78.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Dead by Dawn c29a78.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Late Risers 51fbbc.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Late Risers 51fbbc.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Late Risers 51fbbc.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Late Risers 51fbbc.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Mourning Chorus 24c385.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Mourning Chorus 24c385.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Mourning Chorus 24c385.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Mourning Chorus 24c385.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Night on the Town 2bd90b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Night on the Town 2bd90b.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Night on the Town 2bd90b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Model_Bag Night on the Town 2bd90b.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood ac895d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood ac895d.ttslua index 40fe71a43..49836c550 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood ac895d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood ac895d.ttslua @@ -1,21 +1,21 @@ -name = 'Flesh' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Flesh' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood f5db25.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood f5db25.ttslua index 40fe71a43..49836c550 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood f5db25.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Tile Flesh and Blood f5db25.ttslua @@ -1,21 +1,21 @@ -name = 'Flesh' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Flesh' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Token Generic Campaign Log eda22b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Token Generic Campaign Log eda22b.ttslua index d5fb74c82..588598831 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Token Generic Campaign Log eda22b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Flesh and Blood 613b64/Custom_Token Generic Campaign Log eda22b.ttslua @@ -1,651 +1,651 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --1st Player Experience - { - pos = {-1.080,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --1st Player Physical Trauma - { - pos = {-1.270,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --1st Player Mental Trauma - { - pos = {-1.000,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Experience - { - pos = {-0.251,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --2nd Player Physical Trauma - { - pos = {-0.441,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Mental Trauma - { - pos = {-0.171,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Experience - { - pos = {0.579,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --3rd Player Physical Trauma - { - pos = {0.389,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Mental Trauma - { - pos = {0.659,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Experience - { - pos = {1.407,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --4th Player Physical Trauma - { - pos = {1.217,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Mental Trauma - { - pos = {1.487,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --1st Player Name - { - pos = {-1.265,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Investigator - { - pos = {-1.265,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Story Assets/Weaknesses - { - pos = {-1.265,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Name - { - pos = {-0.436,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Investigator - { - pos = {-0.436,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Story Assets/Weaknesses - { - pos = {-0.436,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Name - { - pos = {0.394,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Investigator - { - pos = {0.394,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Story Assets/Weaknesses - { - pos = {0.394,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Name - { - pos = {1.222,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Investigator - { - pos = {1.222,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Story Assets/Weaknesses - { - pos = {1.222,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.930,0.1,0.930}, - rows = 27, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.820,0.1,0.707}, - rows = 20, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Killed and Insane Investigators - { - pos = {1.010,0.1,1.700}, - rows = 5, - width = 7400, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --1st Player Experience + { + pos = {-1.080,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --1st Player Physical Trauma + { + pos = {-1.270,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --1st Player Mental Trauma + { + pos = {-1.000,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Experience + { + pos = {-0.251,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --2nd Player Physical Trauma + { + pos = {-0.441,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Mental Trauma + { + pos = {-0.171,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Experience + { + pos = {0.579,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --3rd Player Physical Trauma + { + pos = {0.389,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Mental Trauma + { + pos = {0.659,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Experience + { + pos = {1.407,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --4th Player Physical Trauma + { + pos = {1.217,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Mental Trauma + { + pos = {1.487,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --1st Player Name + { + pos = {-1.265,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Investigator + { + pos = {-1.265,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Story Assets/Weaknesses + { + pos = {-1.265,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Name + { + pos = {-0.436,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Investigator + { + pos = {-0.436,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Story Assets/Weaknesses + { + pos = {-0.436,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Name + { + pos = {0.394,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Investigator + { + pos = {0.394,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Story Assets/Weaknesses + { + pos = {0.394,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Name + { + pos = {1.222,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Investigator + { + pos = {1.222,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Story Assets/Weaknesses + { + pos = {1.222,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.930,0.1,0.930}, + rows = 27, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.820,0.1,0.707}, + rows = 20, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Killed and Insane Investigators + { + pos = {1.010,0.1,1.700}, + rows = 5, + width = 7400, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard b7af99.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard b7af99.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard b7af99.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard b7af99.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard e19c97.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard e19c97.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard e19c97.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Eternal Slumber 9ff406/Custom_Token Scenario - EasyStandard e19c97.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - EasyStandard afc7b5.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - EasyStandard afc7b5.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - EasyStandard afc7b5.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - EasyStandard afc7b5.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - HardExpert 9ed124.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - HardExpert 9ed124.ttslua index 1c555f04c..67da25eae 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - HardExpert 9ed124.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Model_Bag The Night's Usurper 578bcb/Custom_Token Scenario - HardExpert 9ed124.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {0,0,0,98} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,1.45}, - height=600, - width=1000, - alignment = 3, - scale={x=1, y=1, z=1}, - font_size=350, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {0,0,0,98} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,1.45}, + height=600, + width=1000, + alignment = 3, + scale={x=1, y=1, z=1}, + font_size=350, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Tile Guardians of the Abyss 82e1ed.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Tile Guardians of the Abyss 82e1ed.ttslua index 613d25c00..c7cae53da 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Tile Guardians of the Abyss 82e1ed.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Guardians of the Abyss ee987d/Custom_Tile Guardians of the Abyss 82e1ed.ttslua @@ -1,21 +1,21 @@ -name = 'Guardians of the Abyss' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Guardians of the Abyss' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8/Custom_Tile Happy's Funhouse c5008a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8/Custom_Tile Happy's Funhouse c5008a.ttslua index a6a523bb3..8a7490ca8 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8/Custom_Tile Happy's Funhouse c5008a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Happy's Funhouse e7d9f8/Custom_Tile Happy's Funhouse c5008a.ttslua @@ -1,21 +1,21 @@ -name = 'Happys Funhouse' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Happys Funhouse' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 1 Bread and Circuses 16ceab.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 1 Bread and Circuses 16ceab.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 1 Bread and Circuses 16ceab.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 1 Bread and Circuses 16ceab.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 2 Enter the Dragon 4f944f.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 2 Enter the Dragon 4f944f.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 2 Enter the Dragon 4f944f.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 2 Enter the Dragon 4f944f.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 3 Bon Voyage 49dfb9.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 3 Bon Voyage 49dfb9.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 3 Bon Voyage 49dfb9.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 3 Bon Voyage 49dfb9.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 4 Cost of Azure 0fad66.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 4 Cost of Azure 0fad66.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 4 Cost of Azure 0fad66.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Model_Bag 4 Cost of Azure 0fad66.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Tile Bread and Circuses 82e1ed.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Tile Bread and Circuses 82e1ed.ttslua index d47035472..bd968c218 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Tile Bread and Circuses 82e1ed.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Idol Thoughts 2d417b/Custom_Tile Bread and Circuses 82e1ed.ttslua @@ -1,21 +1,21 @@ -name = 'Bread and Circuses' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Bread and Circuses' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c.ttslua index 5534586ac..979aaf560 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c/Custom_Tile The Initiation bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c/Custom_Tile The Initiation bbb70a.ttslua index 497ce1745..4048d1eb0 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c/Custom_Tile The Initiation bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag In Blackest Pits 68380c/Custom_Tile The Initiation bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'The Initiation' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'The Initiation' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0/Custom_Tile Into the Shadowlands 770021.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0/Custom_Tile Into the Shadowlands 770021.ttslua index 96b1aaa66..4e75f9bfd 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0/Custom_Tile Into the Shadowlands 770021.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 1 Dark Reflections c1aad0/Custom_Tile Into the Shadowlands 770021.ttslua @@ -1,21 +1,21 @@ -name = 'Into the Shadowlands' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Into the Shadowlands' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 2 Endless Horizons b1bc62.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 2 Endless Horizons b1bc62.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 2 Endless Horizons b1bc62.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Into the Shadowlands 019847/Bag 2 Endless Horizons b1bc62.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48/Custom_Tile Jenny's Choice bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48/Custom_Tile Jenny's Choice bbb70a.ttslua index f1cde3b4e..1182c3163 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48/Custom_Tile Jenny's Choice bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Jenny's Choice a61b48/Custom_Tile Jenny's Choice bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'Jennys Choice' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Jennys Choice' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Investigators fba392.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Investigators fba392.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Investigators fba392.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Investigators fba392.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Izanami's Delegates b34bec.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Izanami's Delegates b34bec.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Izanami's Delegates b34bec.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Izanami's Delegates b34bec.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Player Cards 64ad17.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Player Cards 64ad17.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Player Cards 64ad17.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Player Cards 64ad17.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 1 - Modorimonogatari f051fc.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 1 - Modorimonogatari f051fc.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 1 - Modorimonogatari f051fc.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 1 - Modorimonogatari f051fc.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2A - Toshimonogatari 4076cd.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2A - Toshimonogatari 4076cd.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2A - Toshimonogatari 4076cd.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2A - Toshimonogatari 4076cd.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2B - Inarimonogatari ad56f2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2B - Inarimonogatari ad56f2.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2B - Inarimonogatari ad56f2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2B - Inarimonogatari ad56f2.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Inarimonogatari first, choose this bag 1a6190.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Inarimonogatari first, choose this bag 1a6190.ttslua index 103cb00e5..053fbbacb 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Inarimonogatari first, choose this bag 1a6190.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Inarimonogatari first, choose this bag 1a6190.ttslua @@ -1,547 +1,547 @@ - -- Utility memory bag by Directsun --- Version 2.6.0 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - buttonIndexMap = {} - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Workaround for custom PDFs - if obj.Book then - objPos.y = objPos.y + 0.5 - end - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - buttonIndexMap[obj.getGUID()] = howManyButtons - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - self.createButton({ - label="Selection", click_function="editDragSelection", function_owner=self, - position={0,0.3,2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(obj, move) - local index = buttonIndexMap[obj.getGUID()] - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - -function editDragSelection(bagObj, player, remove) - local selectedObjs = Player[player].getSelectedObjects() - if not remove then - for _, obj in ipairs(selectedObjs) do - local index = buttonIndexMap[obj.getGUID()] - --Ignore if already in the memory list, or does not have a button - if index and not memoryList[obj.getGUID()] then - self.editButton({index=index, color={0,1,0,0.6}}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - end - end - else - for _, obj in ipairs(selectedObjs) do - local index = buttonIndexMap[obj.getGUID()] - if index and memoryList[obj.getGUID()] then - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end - end - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Move", click_function="buttonClick_transpose", function_owner=self, - position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end + -- Utility memory bag by Directsun +-- Version 2.6.0 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + buttonIndexMap = {} + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Workaround for custom PDFs + if obj.Book then + objPos.y = objPos.y + 0.5 + end + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + buttonIndexMap[obj.getGUID()] = howManyButtons + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + self.createButton({ + label="Selection", click_function="editDragSelection", function_owner=self, + position={0,0.3,2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(obj, move) + local index = buttonIndexMap[obj.getGUID()] + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +function editDragSelection(bagObj, player, remove) + local selectedObjs = Player[player].getSelectedObjects() + if not remove then + for _, obj in ipairs(selectedObjs) do + local index = buttonIndexMap[obj.getGUID()] + --Ignore if already in the memory list, or does not have a button + if index and not memoryList[obj.getGUID()] then + self.editButton({index=index, color={0,1,0,0.6}}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + end + end + else + for _, obj in ipairs(selectedObjs) do + local index = buttonIndexMap[obj.getGUID()] + if index and memoryList[obj.getGUID()] then + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end + end + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Move", click_function="buttonClick_transpose", function_owner=self, + position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Toshimonogatari first, choose this bag 91392f.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Toshimonogatari first, choose this bag 91392f.ttslua index 103cb00e5..053fbbacb 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Toshimonogatari first, choose this bag 91392f.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 2S - Shinkansenmonogatari 8221db/Bag If you completed Toshimonogatari first, choose this bag 91392f.ttslua @@ -1,547 +1,547 @@ - -- Utility memory bag by Directsun --- Version 2.6.0 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - buttonIndexMap = {} - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Workaround for custom PDFs - if obj.Book then - objPos.y = objPos.y + 0.5 - end - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - buttonIndexMap[obj.getGUID()] = howManyButtons - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - self.createButton({ - label="Selection", click_function="editDragSelection", function_owner=self, - position={0,0.3,2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(obj, move) - local index = buttonIndexMap[obj.getGUID()] - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - -function editDragSelection(bagObj, player, remove) - local selectedObjs = Player[player].getSelectedObjects() - if not remove then - for _, obj in ipairs(selectedObjs) do - local index = buttonIndexMap[obj.getGUID()] - --Ignore if already in the memory list, or does not have a button - if index and not memoryList[obj.getGUID()] then - self.editButton({index=index, color={0,1,0,0.6}}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - end - end - else - for _, obj in ipairs(selectedObjs) do - local index = buttonIndexMap[obj.getGUID()] - if index and memoryList[obj.getGUID()] then - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end - end - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Move", click_function="buttonClick_transpose", function_owner=self, - position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end + -- Utility memory bag by Directsun +-- Version 2.6.0 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + buttonIndexMap = {} + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Workaround for custom PDFs + if obj.Book then + objPos.y = objPos.y + 0.5 + end + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + buttonIndexMap[obj.getGUID()] = howManyButtons + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + self.createButton({ + label="Selection", click_function="editDragSelection", function_owner=self, + position={0,0.3,2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(obj, move) + local index = buttonIndexMap[obj.getGUID()] + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +function editDragSelection(bagObj, player, remove) + local selectedObjs = Player[player].getSelectedObjects() + if not remove then + for _, obj in ipairs(selectedObjs) do + local index = buttonIndexMap[obj.getGUID()] + --Ignore if already in the memory list, or does not have a button + if index and not memoryList[obj.getGUID()] then + self.editButton({index=index, color={0,1,0,0.6}}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + end + end + else + for _, obj in ipairs(selectedObjs) do + local index = buttonIndexMap[obj.getGUID()] + if index and memoryList[obj.getGUID()] then + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end + end + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Move", click_function="buttonClick_transpose", function_owner=self, + position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 3 - Yamamonogatari b99de3.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 3 - Yamamonogatari b99de3.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 3 - Yamamonogatari b99de3.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 3 - Yamamonogatari b99de3.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 4 - Houkaimonogatari 8f297e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 4 - Houkaimonogatari 8f297e.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 4 - Houkaimonogatari 8f297e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 4 - Houkaimonogatari 8f297e.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 5 - Fumeimonogatari b86938.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 5 - Fumeimonogatari b86938.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 5 - Fumeimonogatari b86938.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Model_Bag Scenario 5 - Fumeimonogatari b86938.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Tile Kaimonogatari f5db25.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Tile Kaimonogatari f5db25.ttslua index da38fca54..a559005a4 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Tile Kaimonogatari f5db25.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Tile Kaimonogatari f5db25.ttslua @@ -1,21 +1,21 @@ -name = 'Kaimonogatari' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Kaimonogatari' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Token Monogatari Campaign Log eda22b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Token Monogatari Campaign Log eda22b.ttslua index db191365f..f4ffeef32 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Token Monogatari Campaign Log eda22b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kaimonogatari 2df25a/Custom_Token Monogatari Campaign Log eda22b.ttslua @@ -1,75 +1,75 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) ]] --Prologue { @@ -160,572 +160,572 @@ defaultButtonData = { pos = {0.87,0.1,-0.092}, size = 260, state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --1st Player Experience + { + pos = {-1.205,0.1,-1.115}, + size = 700, + value = 0, + hideBG = true + }, + --1st Player Physical Trauma + { + pos = {-1.418,0.1,-0.962}, + size = 500, + value = 0, + hideBG = true + }, + --1st Player Mental Trauma + { + pos = {-1.165,0.1,-0.962}, + size = 500, + value = 0, + hideBG = true + }, + --2nd Player Experience + { + pos = {-0.513,0.1,-1.115}, + size = 700, + value = 0, + hideBG = true + }, + --2nd Player Physical Trauma + { + pos = {-0.73,0.1,-0.962}, + size = 500, + value = 0, + hideBG = true + }, + --2nd Player Mental Trauma + { + pos = {-0.48,0.1,-0.962}, + size = 500, + value = 0, + hideBG = true + }, + --3rd Player Experience + { + pos = {-1.205,0.1,-0.045}, + size = 700, + value = 0, + hideBG = true + }, + --3rd Player Physical Trauma + { + pos = {-1.418,0.1,0.12}, + size = 500, + value = 0, + hideBG = true + }, + --3rd Player Mental Trauma + { + pos = {-1.165,0.1,0.12}, + size = 500, + value = 0, + hideBG = true + }, + --4th Player Experience + { + pos = {-0.513,0.1,-0.045}, + size = 700, + value = 0, + hideBG = true + }, + --4th Player Physical Trauma + { + pos = {-0.73,0.1,0.12}, + size = 500, + value = 0, + hideBG = true + }, + --4th Player Mental Trauma + { + pos = {-0.48,0.1,0.12}, + size = 500, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --1st Player Name + { + pos = {-1.42,0.1,-1.381}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Investigator + { + pos = {-1.42,0.1,-1.245}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Story Assets/Weaknesses + { + pos = {-1.42,0.1,-0.63}, + rows = 6, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Name + { + pos = {-0.73,0.1,-1.381}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Investigator + { + pos = {-0.73,0.1,-1.245}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Story Assets/Weaknesses + { + pos = {-0.73,0.1,-0.63}, + rows = 6, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Name + { + pos = {-1.42,0.1,-0.31}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Investigator + { + pos = {-1.42,0.1,-0.17}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Story Assets/Weaknesses + { + pos = {-1.42,0.1,0.38}, + rows = 4, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Name + { + pos = {-0.73,0.1,-0.31}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Investigator + { + pos = {-0.73,0.1,-0.17}, + rows = 1, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Story Assets/Weaknesses + { + pos = {-0.73,0.1,0.38}, + rows = 4, + width = 2800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {0.41,0.1,0.52}, + rows = 12, + width = 5800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --1st Player Experience - { - pos = {-1.205,0.1,-1.115}, - size = 700, - value = 0, - hideBG = true - }, - --1st Player Physical Trauma - { - pos = {-1.418,0.1,-0.962}, - size = 500, - value = 0, - hideBG = true - }, - --1st Player Mental Trauma - { - pos = {-1.165,0.1,-0.962}, - size = 500, - value = 0, - hideBG = true - }, - --2nd Player Experience - { - pos = {-0.513,0.1,-1.115}, - size = 700, - value = 0, - hideBG = true - }, - --2nd Player Physical Trauma - { - pos = {-0.73,0.1,-0.962}, - size = 500, - value = 0, - hideBG = true - }, - --2nd Player Mental Trauma - { - pos = {-0.48,0.1,-0.962}, - size = 500, - value = 0, - hideBG = true - }, - --3rd Player Experience - { - pos = {-1.205,0.1,-0.045}, - size = 700, - value = 0, - hideBG = true - }, - --3rd Player Physical Trauma - { - pos = {-1.418,0.1,0.12}, - size = 500, - value = 0, - hideBG = true - }, - --3rd Player Mental Trauma - { - pos = {-1.165,0.1,0.12}, - size = 500, - value = 0, - hideBG = true - }, - --4th Player Experience - { - pos = {-0.513,0.1,-0.045}, - size = 700, - value = 0, - hideBG = true - }, - --4th Player Physical Trauma - { - pos = {-0.73,0.1,0.12}, - size = 500, - value = 0, - hideBG = true - }, - --4th Player Mental Trauma - { - pos = {-0.48,0.1,0.12}, - size = 500, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --1st Player Name - { - pos = {-1.42,0.1,-1.381}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Investigator - { - pos = {-1.42,0.1,-1.245}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Story Assets/Weaknesses - { - pos = {-1.42,0.1,-0.63}, - rows = 6, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Name - { - pos = {-0.73,0.1,-1.381}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Investigator - { - pos = {-0.73,0.1,-1.245}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Story Assets/Weaknesses - { - pos = {-0.73,0.1,-0.63}, - rows = 6, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Name - { - pos = {-1.42,0.1,-0.31}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Investigator - { - pos = {-1.42,0.1,-0.17}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Story Assets/Weaknesses - { - pos = {-1.42,0.1,0.38}, - rows = 4, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Name - { - pos = {-0.73,0.1,-0.31}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Investigator - { - pos = {-0.73,0.1,-0.17}, - rows = 1, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Story Assets/Weaknesses - { - pos = {-0.73,0.1,0.38}, - rows = 4, - width = 2800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {0.41,0.1,0.52}, - rows = 12, - width = 5800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Killed and Insane Investigators - { - pos = {-1.26,0.1,0.837}, - rows = 4, - width = 5600, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end + --Killed and Insane Investigators + { + pos = {-1.26,0.1,0.837}, + rows = 4, + width = 5600, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Dziwny Przypadek Benedicta Burtona bd069f.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Dziwny Przypadek Benedicta Burtona bd069f.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Dziwny Przypadek Benedicta Burtona bd069f.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Dziwny Przypadek Benedicta Burtona bd069f.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Nieuchwytny 31a93a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Nieuchwytny 31a93a.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Nieuchwytny 31a93a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Nieuchwytny 31a93a.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Podniebny Koncert 2889f0.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Podniebny Koncert 2889f0.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Podniebny Koncert 2889f0.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Podniebny Koncert 2889f0.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Przeznacznenie w Red Hook 1e00a9.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Przeznacznenie w Red Hook 1e00a9.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Przeznacznenie w Red Hook 1e00a9.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Kiedy sny Stają się Rzeczywiścią acdf16/Bag Przeznacznenie w Red Hook 1e00a9.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8/Custom_Tile Knightfall 271ce2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8/Custom_Tile Knightfall 271ce2.ttslua index c2370fa18..02c9b2688 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8/Custom_Tile Knightfall 271ce2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Knightfall df62e8/Custom_Tile Knightfall 271ce2.ttslua @@ -1,21 +1,21 @@ -name = 'Knightfall' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Knightfall' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca/Custom_Tile Last Call at Roxie's 567db0.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca/Custom_Tile Last Call at Roxie's 567db0.ttslua index 5206cda4e..7c6288894 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca/Custom_Tile Last Call at Roxie's 567db0.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Last Call at Roxie's c6a1ca/Custom_Tile Last Call at Roxie's 567db0.ttslua @@ -1,21 +1,21 @@ -name = 'Last Call at Roxies' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Last Call at Roxies' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8/Custom_Tile Core Difficulty aae2b1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8/Custom_Tile Core Difficulty aae2b1.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8/Custom_Tile Core Difficulty aae2b1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Masks of Nyarlathotep – New York 94a1f8/Custom_Tile Core Difficulty aae2b1.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780/Custom_Tile Murder at the Excelsior Hotel bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780/Custom_Tile Murder at the Excelsior Hotel bbb70a.ttslua index 46732a4a2..6f70e0940 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780/Custom_Tile Murder at the Excelsior Hotel bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Murder at the Excelsior Hotel 01d780/Custom_Tile Murder at the Excelsior Hotel bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'Excelsior' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Excelsior' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 1 147dea.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 1 147dea.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 1 147dea.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 1 147dea.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 2 7f9f0d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 2 7f9f0d.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 2 7f9f0d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 2 7f9f0d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 3 df5156.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 3 df5156.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 3 df5156.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Bag Part 3 df5156.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Custom_Tile Core Difficulty ea0896.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Custom_Tile Core Difficulty ea0896.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Custom_Tile Core Difficulty ea0896.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag North Country Cycle aaceca/Custom_Tile Core Difficulty ea0896.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50.ttslua index ed7a62e7d..45f110e8b 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a.ttslua index 1d754d17c..409896272 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a/Custom_Tile Core Difficulty 56a08b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a/Custom_Tile Core Difficulty 56a08b.ttslua index 476f361a0..e79bc79e7 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a/Custom_Tile Core Difficulty 56a08b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 1 Eye on the Prize e54f2a/Custom_Tile Core Difficulty 56a08b.ttslua @@ -1,21 +1,21 @@ -name = 'Of Sphinx' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Of Sphinx' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 2 Chaos in Cairo 6e0236.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 2 Chaos in Cairo 6e0236.ttslua index 1d754d17c..409896272 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 2 Chaos in Cairo 6e0236.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 2 Chaos in Cairo 6e0236.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 3 The Will to Triump 6d8dad.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 3 The Will to Triump 6d8dad.ttslua index 1d754d17c..409896272 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 3 The Will to Triump 6d8dad.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Of Sphinx and Sands eeeb50/Bag 3 The Will to Triump 6d8dad.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202.ttslua index d88f19b4b..a085f3c96 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Midnight in Paris 7cda3f.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Midnight in Paris 7cda3f.ttslua index 360f86347..7a4d95fda 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Midnight in Paris 7cda3f.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Midnight in Paris 7cda3f.ttslua @@ -1,505 +1,505 @@ --- Utility memory bag by Directsun --- Version 2.5 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - print("updating memory with moves") - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - print(guid) - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - print(_) - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Move", click_function="buttonClick_transpose", function_owner=self, - position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + print("updating memory with moves") + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + print(guid) + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + print(_) + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Move", click_function="buttonClick_transpose", function_owner=self, + position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Shadows of Brocéliande 7b28eb.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Shadows of Brocéliande 7b28eb.ttslua index a6759c861..a40fbbd64 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Shadows of Brocéliande 7b28eb.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Shadows of Brocéliande 7b28eb.ttslua @@ -1,505 +1,505 @@ --- Utility memory bag by Directsun --- Version 2.5 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - print("updating memory with moves") - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - print(guid) - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - print(_) - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Move", click_function="buttonClick_transpose", function_owner=self, - position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + print("updating memory with moves") + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + print(guid) + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + print(_) + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Move", click_function="buttonClick_transpose", function_owner=self, + position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag The München Conspiracy 286579.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag The München Conspiracy 286579.ttslua index a6759c861..a40fbbd64 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag The München Conspiracy 286579.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag The München Conspiracy 286579.ttslua @@ -1,505 +1,505 @@ --- Utility memory bag by Directsun --- Version 2.5 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - print("updating memory with moves") - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - print(guid) - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - print(_) - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Move", click_function="buttonClick_transpose", function_owner=self, - position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + print("updating memory with moves") + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + print(guid) + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + print(_) + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Move", click_function="buttonClick_transpose", function_owner=self, + position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Tibetan Winds ba2ded.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Tibetan Winds ba2ded.ttslua index 360f86347..7a4d95fda 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Tibetan Winds ba2ded.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Bag Tibetan Winds ba2ded.ttslua @@ -1,505 +1,505 @@ --- Utility memory bag by Directsun --- Version 2.5 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - print("updating memory with moves") - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - print(guid) - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - print(_) - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Move", click_function="buttonClick_transpose", function_owner=self, - position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + print("updating memory with moves") + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + print(guid) + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + print(_) + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0,0.3,-3.6}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0,0.3,-4.4}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0,0.3,-5.2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Move", click_function="buttonClick_transpose", function_owner=self, + position={-2.8,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Custom_Tile Ordo Templi Orientis bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Custom_Tile Ordo Templi Orientis bbb70a.ttslua index 97ed54b6f..606e250c5 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Custom_Tile Ordo Templi Orientis bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Ordo Templi Orientis 7cf202/Custom_Tile Ordo Templi Orientis bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'Ordis' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'Ordis' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag c0897e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag c0897e.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag c0897e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag c0897e.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 1 Nightmare or Dream f39e68.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 1 Nightmare or Dream f39e68.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 1 Nightmare or Dream f39e68.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 1 Nightmare or Dream f39e68.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 2 Awake 6ca52c.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 2 Awake 6ca52c.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 2 Awake 6ca52c.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Bag 2 Awake 6ca52c.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Custom_Tile Core Difficulty 56a08b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Custom_Tile Core Difficulty 56a08b.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Custom_Tile Core Difficulty 56a08b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Parallel Universe 28e0a1/Custom_Tile Core Difficulty 56a08b.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Adding Pokemon To An Existing Campaign 7b57ad.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Adding Pokemon To An Existing Campaign 7b57ad.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Adding Pokemon To An Existing Campaign 7b57ad.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Adding Pokemon To An Existing Campaign 7b57ad.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Basic Pokemon d14543.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Basic Pokemon d14543.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Basic Pokemon d14543.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Basic Pokemon d14543.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Pokemon Investigators 05109d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Pokemon Investigators 05109d.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Pokemon Investigators 05109d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Pokemon Investigators 05109d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1/Custom_Tile Pokemon Eldritch Edition 3837a5.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1/Custom_Tile Pokemon Eldritch Edition 3837a5.ttslua index 71c417e00..5093ba655 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1/Custom_Tile Pokemon Eldritch Edition 3837a5.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 1 The Conjuring e1caf1/Custom_Tile Pokemon Eldritch Edition 3837a5.ttslua @@ -1,21 +1,21 @@ -name = 'Pokemon' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Pokemon' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2a The Winding Road 61801e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2a The Winding Road 61801e.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2a The Winding Road 61801e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2a The Winding Road 61801e.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2b Shipments From The Unknown 13ed7d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2b Shipments From The Unknown 13ed7d.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2b Shipments From The Unknown 13ed7d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 2b Shipments From The Unknown 13ed7d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3a Viridian f040a6.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3a Viridian f040a6.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3a Viridian f040a6.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3a Viridian f040a6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3b Deep Secrets 3da6dd.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3b Deep Secrets 3da6dd.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3b Deep Secrets 3da6dd.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 3b Deep Secrets 3da6dd.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 4 The Unconjuring 52d102.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 4 The Unconjuring 52d102.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 4 The Unconjuring 52d102.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Scenario 4 The Unconjuring 52d102.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15/Custom_Tile Eldritch Safari 3837a5.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15/Custom_Tile Eldritch Safari 3837a5.ttslua index 854b30bd5..749dcbfa9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15/Custom_Tile Eldritch Safari 3837a5.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 1 Eldritch Safari 1fae15/Custom_Tile Eldritch Safari 3837a5.ttslua @@ -1,21 +1,21 @@ -name = 'Safari' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Safari' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf/Custom_Tile Project Cerulean 3837a5.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf/Custom_Tile Project Cerulean 3837a5.ttslua index 937603789..a5c1bbe0b 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf/Custom_Tile Project Cerulean 3837a5.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Side-Story 2 Project Cerulean 4c07bf/Custom_Tile Project Cerulean 3837a5.ttslua @@ -1,21 +1,21 @@ -name = 'Cerulean' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Cerulean' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Upgrade Pokemon 2cea4e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Upgrade Pokemon 2cea4e.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Upgrade Pokemon 2cea4e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Bag Upgrade Pokemon 2cea4e.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Custom_Token Campaign Log eda22b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Custom_Token Campaign Log eda22b.ttslua index d5fb74c82..588598831 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Custom_Token Campaign Log eda22b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Pokemon Eldritch Edition 75fe78/Custom_Token Campaign Log eda22b.ttslua @@ -1,651 +1,651 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --1st Player Experience - { - pos = {-1.080,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --1st Player Physical Trauma - { - pos = {-1.270,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --1st Player Mental Trauma - { - pos = {-1.000,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Experience - { - pos = {-0.251,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --2nd Player Physical Trauma - { - pos = {-0.441,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Mental Trauma - { - pos = {-0.171,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Experience - { - pos = {0.579,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --3rd Player Physical Trauma - { - pos = {0.389,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Mental Trauma - { - pos = {0.659,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Experience - { - pos = {1.407,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --4th Player Physical Trauma - { - pos = {1.217,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Mental Trauma - { - pos = {1.487,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --1st Player Name - { - pos = {-1.265,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Investigator - { - pos = {-1.265,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Story Assets/Weaknesses - { - pos = {-1.265,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Name - { - pos = {-0.436,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Investigator - { - pos = {-0.436,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Story Assets/Weaknesses - { - pos = {-0.436,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Name - { - pos = {0.394,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Investigator - { - pos = {0.394,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Story Assets/Weaknesses - { - pos = {0.394,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Name - { - pos = {1.222,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Investigator - { - pos = {1.222,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Story Assets/Weaknesses - { - pos = {1.222,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.930,0.1,0.930}, - rows = 27, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.820,0.1,0.707}, - rows = 20, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Killed and Insane Investigators - { - pos = {1.010,0.1,1.700}, - rows = 5, - width = 7400, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --1st Player Experience + { + pos = {-1.080,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --1st Player Physical Trauma + { + pos = {-1.270,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --1st Player Mental Trauma + { + pos = {-1.000,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Experience + { + pos = {-0.251,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --2nd Player Physical Trauma + { + pos = {-0.441,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Mental Trauma + { + pos = {-0.171,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Experience + { + pos = {0.579,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --3rd Player Physical Trauma + { + pos = {0.389,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Mental Trauma + { + pos = {0.659,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Experience + { + pos = {1.407,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --4th Player Physical Trauma + { + pos = {1.217,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Mental Trauma + { + pos = {1.487,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --1st Player Name + { + pos = {-1.265,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Investigator + { + pos = {-1.265,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Story Assets/Weaknesses + { + pos = {-1.265,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Name + { + pos = {-0.436,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Investigator + { + pos = {-0.436,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Story Assets/Weaknesses + { + pos = {-0.436,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Name + { + pos = {0.394,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Investigator + { + pos = {0.394,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Story Assets/Weaknesses + { + pos = {0.394,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Name + { + pos = {1.222,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Investigator + { + pos = {1.222,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Story Assets/Weaknesses + { + pos = {1.222,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.930,0.1,0.930}, + rows = 27, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.820,0.1,0.707}, + rows = 20, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Killed and Insane Investigators + { + pos = {1.010,0.1,1.700}, + rows = 5, + width = 7400, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa/Custom_Tile Read or Die b5928a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa/Custom_Tile Read or Die b5928a.ttslua index 42778aed7..0dd8ca8e1 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa/Custom_Tile Read or Die b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Read or Die 9e73fa/Custom_Tile Read or Die b5928a.ttslua @@ -1,21 +1,21 @@ -name = 'Read or Die' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Read or Die' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 1 In Search Of Sanity 961940.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 1 In Search Of Sanity 961940.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 1 In Search Of Sanity 961940.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 1 In Search Of Sanity 961940.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 2 The Thrushmoor Terror eea51b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 2 The Thrushmoor Terror eea51b.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 2 The Thrushmoor Terror eea51b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Bag 2 The Thrushmoor Terror eea51b.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Custom_Tile Strange Aeons 82e1ed.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Custom_Tile Strange Aeons 82e1ed.ttslua index 8f300ba86..e74915067 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Custom_Tile Strange Aeons 82e1ed.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Strange Aeons 2abdd6/Custom_Tile Strange Aeons 82e1ed.ttslua @@ -1,21 +1,21 @@ -name = 'Strange Aeons' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'Strange Aeons' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301/Custom_Tile Stranger Things bc825a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301/Custom_Tile Stranger Things bc825a.ttslua index accf324f6..23e08a4d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301/Custom_Tile Stranger Things bc825a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Stranger Things 408301/Custom_Tile Stranger Things bc825a.ttslua @@ -1,21 +1,21 @@ -name = 'Stranger Things' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Stranger Things' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66.ttslua index 54d591927..0748143c2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 1 Plot Uncovered 67d524.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 1 Plot Uncovered 67d524.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 1 Plot Uncovered 67d524.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 1 Plot Uncovered 67d524.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 2 Dark Waters 90aab1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 2 Dark Waters 90aab1.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 2 Dark Waters 90aab1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 2 Dark Waters 90aab1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 3 Curiosities 20982e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 3 Curiosities 20982e.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 3 Curiosities 20982e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 3 Curiosities 20982e.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 4 Shadow Rails 3a3b5a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 4 Shadow Rails 3a3b5a.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 4 Shadow Rails 3a3b5a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 4 Shadow Rails 3a3b5a.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 5 lair of the Cult 266dcb.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 5 lair of the Cult 266dcb.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 5 lair of the Cult 266dcb.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 5 lair of the Cult 266dcb.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 6 Domain of Baal 84cdaf.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 6 Domain of Baal 84cdaf.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 6 Domain of Baal 84cdaf.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Bag 6 Domain of Baal 84cdaf.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Custom_Tile The Approaching Storm 7521a9.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Custom_Tile The Approaching Storm 7521a9.ttslua index 7af28b4f4..1c0f40de9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Custom_Tile The Approaching Storm 7521a9.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Approaching Storm 0fad66/Custom_Tile The Approaching Storm 7521a9.ttslua @@ -1,21 +1,21 @@ -name = 'Approaching Storm' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Approaching Storm' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Epic Multiplayer 2c10cf.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Epic Multiplayer 2c10cf.ttslua index f82d90245..758efa0e2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Epic Multiplayer 2c10cf.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Epic Multiplayer 2c10cf.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Setup", click_function="buttonClick_setup", function_owner=self, ---- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={1,1,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Setup", click_function="buttonClick_setup", function_owner=self, +--- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={1,1,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Single Group 830305.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Single Group 830305.ttslua index f82d90245..758efa0e2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Single Group 830305.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Bag Single Group 830305.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Setup", click_function="buttonClick_setup", function_owner=self, ---- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={1,1,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Setup", click_function="buttonClick_setup", function_owner=self, +--- position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={1,1,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Custom_Tile The Blob that Ate Everything bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Custom_Tile The Blob that Ate Everything bbb70a.ttslua index ac13f876e..ad353a3f2 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Custom_Tile The Blob that Ate Everything bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Blob that Ate Everything 4dee5a/Custom_Tile The Blob that Ate Everything bbb70a.ttslua @@ -1,25 +1,25 @@ -name = 'The Blob' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +name = 'The Blob' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb/Custom_Tile The Collector 150603.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb/Custom_Tile The Collector 150603.ttslua index af63b7201..91fb38d19 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb/Custom_Tile The Collector 150603.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Collector 9810eb/Custom_Tile The Collector 150603.ttslua @@ -1,21 +1,21 @@ -name = 'The Collector' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Collector' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff/Custom_Tile The Colour out of Space 2e887e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff/Custom_Tile The Colour out of Space 2e887e.ttslua index dbc84856b..9e9359d36 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff/Custom_Tile The Colour out of Space 2e887e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Colour out of Space 5b81ff/Custom_Tile The Colour out of Space 2e887e.ttslua @@ -1,21 +1,21 @@ -name = 'The Colour out of Space' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Colour out of Space' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d/Custom_Tile The Curse of Amultep b3cbc1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d/Custom_Tile The Curse of Amultep b3cbc1.ttslua index 31eb20a69..354659bc7 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d/Custom_Tile The Curse of Amultep b3cbc1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Curse of Amulotep 0d7a8d/Custom_Tile The Curse of Amultep b3cbc1.ttslua @@ -1,21 +1,21 @@ -name = 'The Curse of Amultep' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Curse of Amultep' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9/Custom_Tile The Dying Star 8d62ae.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9/Custom_Tile The Dying Star 8d62ae.ttslua index 75a63c904..931990e74 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9/Custom_Tile The Dying Star 8d62ae.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 1 b310b9/Custom_Tile The Dying Star 8d62ae.ttslua @@ -1,21 +1,21 @@ -name = 'The Dying Star' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Dying Star' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d/Custom_Tile The Dying Star a148f2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d/Custom_Tile The Dying Star a148f2.ttslua index 75a63c904..931990e74 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d/Custom_Tile The Dying Star a148f2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Dying Star bcfff6/Bag Part 2 c2a55d/Custom_Tile The Dying Star a148f2.ttslua @@ -1,21 +1,21 @@ -name = 'The Dying Star' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Dying Star' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a/Custom_Tile The Festival 4b81f6.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a/Custom_Tile The Festival 4b81f6.ttslua index 392b969e5..c8283e89f 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a/Custom_Tile The Festival 4b81f6.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Festival 29d22a/Custom_Tile The Festival 4b81f6.ttslua @@ -1,21 +1,21 @@ -name = 'The Festival' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Festival' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1/Custom_Tile Core Difficulty 9cd1ad.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1/Custom_Tile Core Difficulty 9cd1ad.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1/Custom_Tile Core Difficulty 9cd1ad.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Grand Oak Hotel 4255b1/Custom_Tile Core Difficulty 9cd1ad.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group A 79b534.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group A 79b534.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group A 79b534.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group A 79b534.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group B c7c4c1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group B c7c4c1.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group B c7c4c1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group B c7c4c1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group C c352ac.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group C c352ac.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group C c352ac.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Epic Group C c352ac.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group A 2ea2a2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group A 2ea2a2.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group A 2ea2a2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group A 2ea2a2.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group B 14808b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group B 14808b.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group B 14808b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group B 14808b.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group C 76b476.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group C 76b476.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group C 76b476.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Bag Single Group C 76b476.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Custom_Tile The Labyrinths of Lunacy f4dcee.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Custom_Tile The Labyrinths of Lunacy f4dcee.ttslua index 91793b491..1ef613c2a 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Custom_Tile The Labyrinths of Lunacy f4dcee.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Labyrinths of Lunacy 4c173f/Custom_Tile The Labyrinths of Lunacy f4dcee.ttslua @@ -1,21 +1,21 @@ -name = 'The Labyrinths of Lunacy' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Labyrinths of Lunacy' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2.ttslua index 5aa27be92..d3a91c848 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Tile The Legend of Sleepy Hollow bbb70a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Tile The Legend of Sleepy Hollow bbb70a.ttslua index ed6b304fe..0294acb1d 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Tile The Legend of Sleepy Hollow bbb70a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Tile The Legend of Sleepy Hollow bbb70a.ttslua @@ -1,13 +1,13 @@ -name = 'Sleepy Hollow' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) +name = 'Sleepy Hollow' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Token Generic Campaign Log eda22b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Token Generic Campaign Log eda22b.ttslua index 4ea5509ad..0942cf0ac 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Token Generic Campaign Log eda22b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Legend of Sleepy Hollow b46db2/Custom_Token Generic Campaign Log eda22b.ttslua @@ -1,509 +1,509 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --1st Player Experience - { - pos = {-1.080,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --1st Player Physical Trauma - { - pos = {-1.270,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --1st Player Mental Trauma - { - pos = {-1.000,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Experience - { - pos = {-0.251,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --2nd Player Physical Trauma - { - pos = {-0.441,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Mental Trauma - { - pos = {-0.171,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Experience - { - pos = {0.579,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --3rd Player Physical Trauma - { - pos = {0.389,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Mental Trauma - { - pos = {0.659,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Experience - { - pos = {1.407,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --4th Player Physical Trauma - { - pos = {1.217,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Mental Trauma - { - pos = {1.487,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --1st Player Name - { - pos = {-1.265,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Investigator - { - pos = {-1.265,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Story Assets/Weaknesses - { - pos = {-1.265,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Name - { - pos = {-0.436,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Investigator - { - pos = {-0.436,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Story Assets/Weaknesses - { - pos = {-0.436,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Name - { - pos = {0.394,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Investigator - { - pos = {0.394,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Story Assets/Weaknesses - { - pos = {0.394,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Name - { - pos = {1.222,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Investigator - { - pos = {1.222,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Story Assets/Weaknesses - { - pos = {1.222,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 1 - { - pos = {-0.930,0.1,0.930}, - rows = 27, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes 2 - { - pos = {0.820,0.1,0.707}, - rows = 20, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Killed and Insane Investigators - { - pos = {1.010,0.1,1.700}, - rows = 5, - width = 7400, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -function updateSave() - saved_data = JSON.encode(ref_buttonData) - if disableSave==true then saved_data="" end - self.script_state = saved_data -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end -end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --1st Player Experience + { + pos = {-1.080,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --1st Player Physical Trauma + { + pos = {-1.270,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --1st Player Mental Trauma + { + pos = {-1.000,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Experience + { + pos = {-0.251,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --2nd Player Physical Trauma + { + pos = {-0.441,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Mental Trauma + { + pos = {-0.171,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Experience + { + pos = {0.579,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --3rd Player Physical Trauma + { + pos = {0.389,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Mental Trauma + { + pos = {0.659,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Experience + { + pos = {1.407,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --4th Player Physical Trauma + { + pos = {1.217,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Mental Trauma + { + pos = {1.487,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --1st Player Name + { + pos = {-1.265,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Investigator + { + pos = {-1.265,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Story Assets/Weaknesses + { + pos = {-1.265,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Name + { + pos = {-0.436,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Investigator + { + pos = {-0.436,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Story Assets/Weaknesses + { + pos = {-0.436,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Name + { + pos = {0.394,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Investigator + { + pos = {0.394,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Story Assets/Weaknesses + { + pos = {0.394,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Name + { + pos = {1.222,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Investigator + { + pos = {1.222,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Story Assets/Weaknesses + { + pos = {1.222,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 1 + { + pos = {-0.930,0.1,0.930}, + rows = 27, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes 2 + { + pos = {0.820,0.1,0.707}, + rows = 20, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Killed and Insane Investigators + { + pos = {1.010,0.1,1.700}, + rows = 5, + width = 7400, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +function updateSave() + saved_data = JSON.encode(ref_buttonData) + if disableSave==true then saved_data="" end + self.script_state = saved_data +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55/Custom_Tile A Loving Spouse ea41d9.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55/Custom_Tile A Loving Spouse ea41d9.ttslua index 7ad001427..8c66c0fe3 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55/Custom_Tile A Loving Spouse ea41d9.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 1 A Loving Spouse 4c5c55/Custom_Tile A Loving Spouse ea41d9.ttslua @@ -1,21 +1,21 @@ -name = 'London Set 1' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'London Set 1' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66/Custom_Tile Mrs Tillywingers Cat 0ae91a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66/Custom_Tile Mrs Tillywingers Cat 0ae91a.ttslua index 562cf43bf..392146f03 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66/Custom_Tile Mrs Tillywingers Cat 0ae91a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 2 Mrs Tillywingers Cat c56f66/Custom_Tile Mrs Tillywingers Cat 0ae91a.ttslua @@ -1,21 +1,21 @@ -name = 'London Set 2' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'London Set 2' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3/Custom_Tile Disgracing Alderman Whitney c2736e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3/Custom_Tile Disgracing Alderman Whitney c2736e.ttslua index 83121ac95..8e7652429 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3/Custom_Tile Disgracing Alderman Whitney c2736e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The London Set 0f96ac/Bag 3 Disgracing Alderman Whitn 905ad3/Custom_Tile Disgracing Alderman Whitney c2736e.ttslua @@ -1,21 +1,21 @@ -name = 'London Set 3' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'London Set 3' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12/Custom_Tile The Nephew Calls 54707a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12/Custom_Tile The Nephew Calls 54707a.ttslua index 8849d7feb..a51884f2c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12/Custom_Tile The Nephew Calls 54707a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Nephew Calls 3ddd12/Custom_Tile The Nephew Calls 54707a.ttslua @@ -1,21 +1,21 @@ -name = 'The Nephew Calls' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Nephew Calls' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 1 526ff9.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 1 526ff9.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 1 526ff9.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 1 526ff9.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 2 5b3ac7.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 2 5b3ac7.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 2 5b3ac7.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 2 5b3ac7.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 3 d166f2.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 3 d166f2.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 3 d166f2.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Bag Part 3 d166f2.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Custom_Tile The Outsider d5b06c.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Custom_Tile The Outsider d5b06c.ttslua index 9686b0f8a..c7d360676 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Custom_Tile The Outsider d5b06c.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Outsider 3c175c/Custom_Tile The Outsider d5b06c.ttslua @@ -1,21 +1,21 @@ -name = 'The Outsider' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'The Outsider' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38/Custom_Tile The Pensher Wyrm c606a1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38/Custom_Tile The Pensher Wyrm c606a1.ttslua index e71cfb253..89881072c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38/Custom_Tile The Pensher Wyrm c606a1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Pensher Wyrm 504f38/Custom_Tile The Pensher Wyrm c606a1.ttslua @@ -1,21 +1,21 @@ -name = 'The Pensher Wyrm' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end +name = 'The Pensher Wyrm' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Red Room fa4327.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Red Room fa4327.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Red Room fa4327.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Red Room fa4327.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4/Custom_Tile Core Difficulty ec7a73.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4/Custom_Tile Core Difficulty ec7a73.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4/Custom_Tile Core Difficulty ec7a73.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Stolen Baillius bfefd4/Custom_Tile Core Difficulty ec7a73.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b/Custom_Tile Core Difficulty a751fe.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b/Custom_Tile Core Difficulty a751fe.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b/Custom_Tile Core Difficulty a751fe.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Svalbard Event 7bc42b/Custom_Tile Core Difficulty a751fe.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Model Custom Data Helper c0b834.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Model Custom Data Helper c0b834.ttslua index 2f7f3a921..7db02d708 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Model Custom Data Helper c0b834.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Model Custom Data Helper c0b834.ttslua @@ -1,37 +1,37 @@ --- set true to enable debug logging -DEBUG = false - -function log(message) - if DEBUG then - print(message) - end -end - ---[[ -Known locations and clues. We check this to determine if we should -atttempt to spawn clues, first we look for _ and if -we find nothing we look for -format is [location_guid -> clueCount] -]] -LOCATIONS_DATA_JSON = [[ -{ - "Entrance Hall": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Main Lobby": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Gallery": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Auditorium": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Anechoic Chamber": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Instrument Closet": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Recording Studio": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Rehearsal Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Scene Shop": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Tiring Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Stage Hall": {"type": "fixed", "value": 1, "clueSide": "front"} -} -]] - -LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) - -function onload(save_state) - local playArea = getObjectFromGUID('721ba2') - playArea.call("updateLocations", {self.getGUID()}) -end +-- set true to enable debug logging +DEBUG = false + +function log(message) + if DEBUG then + print(message) + end +end + +--[[ +Known locations and clues. We check this to determine if we should +atttempt to spawn clues, first we look for _ and if +we find nothing we look for +format is [location_guid -> clueCount] +]] +LOCATIONS_DATA_JSON = [[ +{ + "Entrance Hall": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Main Lobby": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Gallery": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Auditorium": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Anechoic Chamber": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Instrument Closet": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Recording Studio": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Rehearsal Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Scene Shop": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Tiring Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Stage Hall": {"type": "fixed", "value": 1, "clueSide": "front"} +} +]] + +LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) + +function onload(save_state) + local playArea = getObjectFromGUID('721ba2') + playArea.call("updateLocations", {self.getGUID()}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Tile The Symphony of Erich Zann f4c93e.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Tile The Symphony of Erich Zann f4c93e.ttslua index 9cecde9ef..e0c809bfe 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Tile The Symphony of Erich Zann f4c93e.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Symphony of Erich Zann b7c6be/Custom_Tile The Symphony of Erich Zann f4c93e.ttslua @@ -1,25 +1,25 @@ -name = 'Erich Zann' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end - -function standaloneClick() - Global.call('fillContainer', {object=self, key=name, mode='standalone'}) -end +name = 'Erich Zann' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end + +function standaloneClick() + Global.call('fillContainer', {object=self, key=name, mode='standalone'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49/Custom_Tile Core Difficulty 2261a5.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49/Custom_Tile Core Difficulty 2261a5.ttslua index c7ea585c8..ce26fb1d9 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49/Custom_Tile Core Difficulty 2261a5.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The Thing in the Woods c90c49/Custom_Tile Core Difficulty 2261a5.ttslua @@ -1,21 +1,21 @@ -name = 'Core Set' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Core Set' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469.ttslua index d4332d4c8..d08a19f8d 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-0.6,0.1,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={0.6,0.3,-2.1}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={0.6,0.3,-2.5}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-0.6,0.3,-2.9}, rotation={0,0,0}, height=220, width=550, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 1 First Contact f70a0d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 1 First Contact f70a0d.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 1 First Contact f70a0d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 1 First Contact f70a0d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 2 Phobos and Deimos 313523.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 2 Phobos and Deimos 313523.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 2 Phobos and Deimos 313523.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 2 Phobos and Deimos 313523.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 3 The Thirsting Void a0d2b1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 3 The Thirsting Void a0d2b1.ttslua index cae387265..013eb65ca 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 3 The Thirsting Void a0d2b1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Model_Bag 3 The Thirsting Void a0d2b1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1* 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor + 2 - objPos.z = objPos.z * globalScaleFactor * 0.9 - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=400, width=400, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPosition(entry.pos) - obj.setRotation(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1* 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + 2 + objPos.z = objPos.z * globalScaleFactor * 0.9 + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=400, width=400, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPosition(entry.pos) + obj.setRotation(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Tile War of the Worlds b5928a.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Tile War of the Worlds b5928a.ttslua index 267e4346b..4a3502c94 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Tile War of the Worlds b5928a.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Tile War of the Worlds b5928a.ttslua @@ -1,21 +1,21 @@ name = 'War of the Worlds' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) -end + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Token War of the Worlds Campaign Log eda22b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Token War of the Worlds Campaign Log eda22b.ttslua index 6011ced73..64a6b9bcb 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Token War of the Worlds Campaign Log eda22b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag The War of the Worlds 19d469/Custom_Token War of the Worlds Campaign Log eda22b.ttslua @@ -1,682 +1,682 @@ ---[[ Character Sheet Template by: MrStump - -You can set up your own character sheet if you follow these steps. - -Step 1) Change the character sheet image - -Right click on the character sheet, click Custom - -Replace the image URL with one for your character sheet - -Click import, make sure your sheet loads - -SAVE THE GAME (the table setup) - -LOAD FROM THAT SAVE YOU JUST MADE - -Step 2) Edit script to fit your character sheet - -Below you will see some general options, and then the big data table - -The data table is what determines how many of which buttons are made - -Checkboxes - -Counters - -Textboxes - -By default, there are 3 of each. You can add more or remove entries - -If you intend to add/remove, be sure only to add/remove ENTRIES - -This is what an entry looks like: - { - pos = {-0.977,0.1,-0.589}, - size = 800, - state = false - }, - -Deleting the whole thing would remove that specific item on the sheet - -Copy and pasting it after another entry would create another - -Each entry type has unique data points (pos, size, state, etc) - -Do not try to add in your own data points or remove them individually - -There is a summary of what each point does at the top of its category - -Step 3) Save and check script changes - -Hit Save & Apply in the script window to save your code - -You can edit your code as needed and Save+Apply as often as needed - -When you are finished, make disableSave = false below then Save+apply - -This enables saving, so your sheet will remember whats on it. - -Bonus) Finding/Editing Positions for elements - I have included a tool to get positions for buttons in {x,y,z} form - Place it where you want the center of your element to be - Then copy the table from the notes (lower right of screen) - You can highlight it and CTRL+C - Paste it into the data table where needed (pos=) - If you want to manually tweek the values: - {0,0,0} is the center of the character sheet - {1,0,0} is right, {-1,0,0} is left - {0,0,-1} is up, {0,0,1} is down - 0.1 for Y is the height off of the page. - If it was 0, it would be down inside the model of the sheet - -Begin editing below: ]] - ---Set this to true while editing and false when you have finished -disableSave = false ---Remember to set this to false once you are done making changes ---Then, after you save & apply it, save your game too - ---Color information for button text (r,g,b, values of 0-1) -buttonFontColor = {0,0,0} ---Color information for button background -buttonColor = {1,1,1} ---Change scale of button (Avoid changing if possible) -buttonScale = {0.1,0.1,0.1} - ---This is the button placement information -defaultButtonData = { - --Add checkboxes - checkbox = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for checkbox - state = default starting value for checkbox (true=checked, false=not) - ]] - --First Contact - { - pos = {-1.730,0.1,1.140}, - size = 500, - state = false - }, - --Phobos and Deimos - { - pos = {-0.968,0.1,1.355}, - size = 500, - state = false - }, - --The Stillness - { - pos = {-1.683,0.1,1.560}, - size = 500, - state = false - }, - --The Thirsting Void - { - pos = {-0.888,0.1,1.746}, - size = 500, - state = false - }, - --End of checkboxes - }, - --Add counters that have a + and - button - counter = { - --[[ - pos = the position (pasted from the helper tool) - size = height/width/font_size for counter - value = default starting value for counter - hideBG = if background of counter is hidden (true=hidden, false=not) - ]] - --1st Player Experience - { - pos = {-1.080,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --1st Player Physical Trauma - { - pos = {-1.270,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --1st Player Mental Trauma - { - pos = {-1.000,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Experience - { - pos = {-0.251,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --2nd Player Physical Trauma - { - pos = {-0.441,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --2nd Player Mental Trauma - { - pos = {-0.171,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Experience - { - pos = {0.579,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --3rd Player Physical Trauma - { - pos = {0.389,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --3rd Player Mental Trauma - { - pos = {0.659,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Experience - { - pos = {1.407,0.1,-1.010}, - size = 800, - value = 0, - hideBG = true - }, - --4th Player Physical Trauma - { - pos = {1.217,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --4th Player Mental Trauma - { - pos = {1.487,0.1,-0.790}, - size = 600, - value = 0, - hideBG = true - }, - --Sacrifices to Nodens - { - pos = {0.890,0.1,1.150}, - size = 1000, - value = 0, - hideBG = true - }, - --End of counters - }, - --Add editable text boxes - textbox = { - --[[ - pos = the position (pasted from the helper tool) - rows = how many lines of text you want for this box - width = how wide the text box is - font_size = size of text. This and "rows" effect overall height - label = what is shown when there is no text. "" = nothing - value = text entered into box. "" = nothing - alignment = Number to indicate how you want text aligned - (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) - ]] - --1st Player Name - { - pos = {-1.265,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Investigator - { - pos = {-1.265,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --1st Player Story Assets/Weaknesses - { - pos = {-1.265,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Name - { - pos = {-0.436,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Investigator - { - pos = {-0.436,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --2nd Player Story Assets/Weaknesses - { - pos = {-0.436,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Name - { - pos = {0.394,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Investigator - { - pos = {0.394,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --3rd Player Story Assets/Weaknesses - { - pos = {0.394,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Name - { - pos = {1.222,0.1,-1.390}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Investigator - { - pos = {1.222,0.1,-1.195}, - rows = 1, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --4th Player Story Assets/Weaknesses - { - pos = {1.222,0.1,-0.420}, - rows = 7, - width = 3800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Campaign Notes - { - pos = {-0.930,0.1,0.620}, - rows = 12, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Evacuated Locations - { - pos = {0.820,0.1,0.500}, - rows = 10, - width = 7800, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --Killed and Insane Investigators - { - pos = {1.010,0.1,1.700}, - rows = 5, - width = 7400, - font_size = 300, - label = "Empty", - value = "", - alignment = 2 - }, - --End of textboxes - } -} - - - ---Lua beyond this point, I recommend doing something more fun with your life - - - ---Save function -local alreadySaving = false -- Copy this too! -function updateSave() - - function string.replaceText(text, old, new) - local b,e = text:find(old,1,true) - if b==nil then - return text - else - return text:sub(1,b-1) .. new .. text:sub(e+1) - end - end - - function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time - end - - function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy - end - - function startSaving() - while alreadySaving do - wait(0.01) - end - alreadySaving = true - local ref_buttonData = deepcopy(ref_buttonData) - local input_values = {} - local checkbox_values = {} - local counter_values = {} - - local GUID = self.getGUID() - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - input_values[counter] = val.value - val.value = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - if val.label != nil then - input_values[counter] = val.label - val.label = "u"..GUID..":iv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - checkbox_values[counter] = val.value - val.value = "u"..GUID..":bv:"..counter.."u" - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - counter_values[counter] = val.value - val.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - counter_values[counter] = val2.value - val2.value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - if val2.change_value != nil then - counter_values[counter] = val2.change_value - val2.change_value = "u"..GUID..":cv:"..counter.."u" - counter = counter + 1 - end - end - end - - end - end - - saved_data = JSON.encode(ref_buttonData) - - local counter = 1 - for _, val in ipairs(ref_buttonData.textbox) do - if val.value != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.value = input_values[counter] - counter = counter + 1 - end - if val.label != nil then - saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) - val.label = input_values[counter] - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.checkbox) do - if val.value != nil then - val.value = checkbox_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - - local counter = 1 - for _, val in ipairs(ref_buttonData.counter) do - if val.value != nil then - val.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - - if val.counters != nil then - for _, val2 in ipairs(val.counters) do - if val2.value != nil then - val2.value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - if val2.change_value != nil then - val2.change_value = counter_values[counter] - saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) - counter = counter + 1 - end - end - end - - end - end - if disableSave==true then saved_data="" end - self.script_state = saved_data - - alreadySaving = false - return 1 - end - startLuaCoroutine(self, "startSaving") -end - ---Startup procedure -function onload(saved_data) - if disableSave==true then saved_data="" end - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - ref_buttonData = loaded_data - else - ref_buttonData = defaultButtonData - end - - spawnedButtonCount = 0 - createCheckbox() - createCounter() - createTextbox() -end - - - ---Click functions for buttons - - - ---Checks or unchecks the given box -function click_checkbox(tableIndex, buttonIndex) - if ref_buttonData.checkbox[tableIndex].state == true then - ref_buttonData.checkbox[tableIndex].state = false - self.editButton({index=buttonIndex, label=""}) - else - ref_buttonData.checkbox[tableIndex].state = true - self.editButton({index=buttonIndex, label=string.char(10008)}) - end - updateSave() -end - ---Applies value to given counter display -function click_counter(tableIndex, buttonIndex, amount) - ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount - self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) - updateSave() -end - ---Updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - ref_buttonData.textbox[i].value = value - updateSave() - end -end - ---Dud function for if you have a background on a counter -function click_none() end - - - ---Button creation - - - ---Makes checkboxes -function createCheckbox() - for i, data in ipairs(ref_buttonData.checkbox) do - --Sets up reference function - local buttonNumber = spawnedButtonCount - local funcName = "checkbox"..i - local func = function() click_checkbox(i, buttonNumber) end - self.setVar(funcName, func) - --Sets up label - local label = "" - if data.state==true then label=string.char(10008) end - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=data.pos, height=data.size, width=data.size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - ---Makes counters -function createCounter() - for i, data in ipairs(ref_buttonData.counter) do - --Sets up display - local displayNumber = spawnedButtonCount - --Sets up label - local label = data.value - --Sets height/width for display - local size = data.size - if data.hideBG == true then size = 0 end - --Creates button and counts it - self.createButton({ - label=label, click_function="click_none", function_owner=self, - position=data.pos, height=size, width=size, - font_size=data.size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up add 1 - local funcName = "counterAdd"..i - local func = function() click_counter(i, displayNumber, 1) end - self.setVar(funcName, func) - --Sets up label - local label = "+" - --Sets up position - local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) - local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} - --Sets up size - local size = data.size / 2 - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - - --Sets up subtract 1 - local funcName = "counterSub"..i - local func = function() click_counter(i, displayNumber, -1) end - self.setVar(funcName, func) - --Sets up label - local label = "-" - --Set up position - local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} - --Creates button and counts it - self.createButton({ - label=label, click_function=funcName, function_owner=self, - position=pos, height=size, width=size, - font_size=size, scale=buttonScale, - color=buttonColor, font_color=buttonFontColor - }) - spawnedButtonCount = spawnedButtonCount + 1 - end -end - -function createTextbox() - for i, data in ipairs(ref_buttonData.textbox) do - --Sets up reference function - local funcName = "textbox"..i - local func = function(_,_,val,sel) click_textbox(i,val,sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = data.label, - alignment = data.alignment, - position = data.pos, - scale = buttonScale, - width = data.width, - height = (data.font_size*data.rows)+24, - font_size = data.font_size, - color = buttonColor, - font_color = buttonFontColor, - value = data.value, - }) - end +--[[ Character Sheet Template by: MrStump + +You can set up your own character sheet if you follow these steps. + +Step 1) Change the character sheet image + -Right click on the character sheet, click Custom + -Replace the image URL with one for your character sheet + -Click import, make sure your sheet loads + -SAVE THE GAME (the table setup) + -LOAD FROM THAT SAVE YOU JUST MADE + +Step 2) Edit script to fit your character sheet + -Below you will see some general options, and then the big data table + -The data table is what determines how many of which buttons are made + -Checkboxes + -Counters + -Textboxes + -By default, there are 3 of each. You can add more or remove entries + -If you intend to add/remove, be sure only to add/remove ENTRIES + -This is what an entry looks like: + { + pos = {-0.977,0.1,-0.589}, + size = 800, + state = false + }, + -Deleting the whole thing would remove that specific item on the sheet + -Copy and pasting it after another entry would create another + -Each entry type has unique data points (pos, size, state, etc) + -Do not try to add in your own data points or remove them individually + -There is a summary of what each point does at the top of its category + +Step 3) Save and check script changes + -Hit Save & Apply in the script window to save your code + -You can edit your code as needed and Save+Apply as often as needed + -When you are finished, make disableSave = false below then Save+apply + -This enables saving, so your sheet will remember whats on it. + +Bonus) Finding/Editing Positions for elements + I have included a tool to get positions for buttons in {x,y,z} form + Place it where you want the center of your element to be + Then copy the table from the notes (lower right of screen) + You can highlight it and CTRL+C + Paste it into the data table where needed (pos=) + If you want to manually tweek the values: + {0,0,0} is the center of the character sheet + {1,0,0} is right, {-1,0,0} is left + {0,0,-1} is up, {0,0,1} is down + 0.1 for Y is the height off of the page. + If it was 0, it would be down inside the model of the sheet + +Begin editing below: ]] + +--Set this to true while editing and false when you have finished +disableSave = false +--Remember to set this to false once you are done making changes +--Then, after you save & apply it, save your game too + +--Color information for button text (r,g,b, values of 0-1) +buttonFontColor = {0,0,0} +--Color information for button background +buttonColor = {1,1,1} +--Change scale of button (Avoid changing if possible) +buttonScale = {0.1,0.1,0.1} + +--This is the button placement information +defaultButtonData = { + --Add checkboxes + checkbox = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for checkbox + state = default starting value for checkbox (true=checked, false=not) + ]] + --First Contact + { + pos = {-1.730,0.1,1.140}, + size = 500, + state = false + }, + --Phobos and Deimos + { + pos = {-0.968,0.1,1.355}, + size = 500, + state = false + }, + --The Stillness + { + pos = {-1.683,0.1,1.560}, + size = 500, + state = false + }, + --The Thirsting Void + { + pos = {-0.888,0.1,1.746}, + size = 500, + state = false + }, + --End of checkboxes + }, + --Add counters that have a + and - button + counter = { + --[[ + pos = the position (pasted from the helper tool) + size = height/width/font_size for counter + value = default starting value for counter + hideBG = if background of counter is hidden (true=hidden, false=not) + ]] + --1st Player Experience + { + pos = {-1.080,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --1st Player Physical Trauma + { + pos = {-1.270,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --1st Player Mental Trauma + { + pos = {-1.000,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Experience + { + pos = {-0.251,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --2nd Player Physical Trauma + { + pos = {-0.441,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --2nd Player Mental Trauma + { + pos = {-0.171,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Experience + { + pos = {0.579,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --3rd Player Physical Trauma + { + pos = {0.389,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --3rd Player Mental Trauma + { + pos = {0.659,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Experience + { + pos = {1.407,0.1,-1.010}, + size = 800, + value = 0, + hideBG = true + }, + --4th Player Physical Trauma + { + pos = {1.217,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --4th Player Mental Trauma + { + pos = {1.487,0.1,-0.790}, + size = 600, + value = 0, + hideBG = true + }, + --Sacrifices to Nodens + { + pos = {0.890,0.1,1.150}, + size = 1000, + value = 0, + hideBG = true + }, + --End of counters + }, + --Add editable text boxes + textbox = { + --[[ + pos = the position (pasted from the helper tool) + rows = how many lines of text you want for this box + width = how wide the text box is + font_size = size of text. This and "rows" effect overall height + label = what is shown when there is no text. "" = nothing + value = text entered into box. "" = nothing + alignment = Number to indicate how you want text aligned + (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified) + ]] + --1st Player Name + { + pos = {-1.265,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Investigator + { + pos = {-1.265,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --1st Player Story Assets/Weaknesses + { + pos = {-1.265,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Name + { + pos = {-0.436,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Investigator + { + pos = {-0.436,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --2nd Player Story Assets/Weaknesses + { + pos = {-0.436,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Name + { + pos = {0.394,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Investigator + { + pos = {0.394,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --3rd Player Story Assets/Weaknesses + { + pos = {0.394,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Name + { + pos = {1.222,0.1,-1.390}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Investigator + { + pos = {1.222,0.1,-1.195}, + rows = 1, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --4th Player Story Assets/Weaknesses + { + pos = {1.222,0.1,-0.420}, + rows = 7, + width = 3800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Campaign Notes + { + pos = {-0.930,0.1,0.620}, + rows = 12, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Evacuated Locations + { + pos = {0.820,0.1,0.500}, + rows = 10, + width = 7800, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --Killed and Insane Investigators + { + pos = {1.010,0.1,1.700}, + rows = 5, + width = 7400, + font_size = 300, + label = "Empty", + value = "", + alignment = 2 + }, + --End of textboxes + } +} + + + +--Lua beyond this point, I recommend doing something more fun with your life + + + +--Save function +local alreadySaving = false -- Copy this too! +function updateSave() + + function string.replaceText(text, old, new) + local b,e = text:find(old,1,true) + if b==nil then + return text + else + return text:sub(1,b-1) .. new .. text:sub(e+1) + end + end + + function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time + end + + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + + function startSaving() + while alreadySaving do + wait(0.01) + end + alreadySaving = true + local ref_buttonData = deepcopy(ref_buttonData) + local input_values = {} + local checkbox_values = {} + local counter_values = {} + + local GUID = self.getGUID() + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + input_values[counter] = val.value + val.value = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + if val.label != nil then + input_values[counter] = val.label + val.label = "u"..GUID..":iv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + checkbox_values[counter] = val.value + val.value = "u"..GUID..":bv:"..counter.."u" + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + counter_values[counter] = val.value + val.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + counter_values[counter] = val2.value + val2.value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + if val2.change_value != nil then + counter_values[counter] = val2.change_value + val2.change_value = "u"..GUID..":cv:"..counter.."u" + counter = counter + 1 + end + end + end + + end + end + + saved_data = JSON.encode(ref_buttonData) + + local counter = 1 + for _, val in ipairs(ref_buttonData.textbox) do + if val.value != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.value = input_values[counter] + counter = counter + 1 + end + if val.label != nil then + saved_data = saved_data:replaceText("u"..GUID..":iv:"..counter.."u", string.gsub(input_values[counter], "[\\\"']", "\\%1")) + val.label = input_values[counter] + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.checkbox) do + if val.value != nil then + val.value = checkbox_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":bv:"..counter.."u", string.gsub(checkbox_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + + local counter = 1 + for _, val in ipairs(ref_buttonData.counter) do + if val.value != nil then + val.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + + if val.counters != nil then + for _, val2 in ipairs(val.counters) do + if val2.value != nil then + val2.value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + if val2.change_value != nil then + val2.change_value = counter_values[counter] + saved_data = saved_data:replaceText("u"..GUID..":cv:"..counter.."u", string.gsub(counter_values[counter], "[\\\"']", "\\%1")) + counter = counter + 1 + end + end + end + + end + end + if disableSave==true then saved_data="" end + self.script_state = saved_data + + alreadySaving = false + return 1 + end + startLuaCoroutine(self, "startSaving") +end + +--Startup procedure +function onload(saved_data) + if disableSave==true then saved_data="" end + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + ref_buttonData = loaded_data + else + ref_buttonData = defaultButtonData + end + + spawnedButtonCount = 0 + createCheckbox() + createCounter() + createTextbox() +end + + + +--Click functions for buttons + + + +--Checks or unchecks the given box +function click_checkbox(tableIndex, buttonIndex) + if ref_buttonData.checkbox[tableIndex].state == true then + ref_buttonData.checkbox[tableIndex].state = false + self.editButton({index=buttonIndex, label=""}) + else + ref_buttonData.checkbox[tableIndex].state = true + self.editButton({index=buttonIndex, label=string.char(10008)}) + end + updateSave() +end + +--Applies value to given counter display +function click_counter(tableIndex, buttonIndex, amount) + ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount + self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value}) + updateSave() +end + +--Updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + ref_buttonData.textbox[i].value = value + updateSave() + end +end + +--Dud function for if you have a background on a counter +function click_none() end + + + +--Button creation + + + +--Makes checkboxes +function createCheckbox() + for i, data in ipairs(ref_buttonData.checkbox) do + --Sets up reference function + local buttonNumber = spawnedButtonCount + local funcName = "checkbox"..i + local func = function() click_checkbox(i, buttonNumber) end + self.setVar(funcName, func) + --Sets up label + local label = "" + if data.state==true then label=string.char(10008) end + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=data.pos, height=data.size, width=data.size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +--Makes counters +function createCounter() + for i, data in ipairs(ref_buttonData.counter) do + --Sets up display + local displayNumber = spawnedButtonCount + --Sets up label + local label = data.value + --Sets height/width for display + local size = data.size + if data.hideBG == true then size = 0 end + --Creates button and counts it + self.createButton({ + label=label, click_function="click_none", function_owner=self, + position=data.pos, height=size, width=size, + font_size=data.size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up add 1 + local funcName = "counterAdd"..i + local func = function() click_counter(i, displayNumber, 1) end + self.setVar(funcName, func) + --Sets up label + local label = "+" + --Sets up position + local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002) + local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]} + --Sets up size + local size = data.size / 2 + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + + --Sets up subtract 1 + local funcName = "counterSub"..i + local func = function() click_counter(i, displayNumber, -1) end + self.setVar(funcName, func) + --Sets up label + local label = "-" + --Set up position + local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]} + --Creates button and counts it + self.createButton({ + label=label, click_function=funcName, function_owner=self, + position=pos, height=size, width=size, + font_size=size, scale=buttonScale, + color=buttonColor, font_color=buttonFontColor + }) + spawnedButtonCount = spawnedButtonCount + 1 + end +end + +function createTextbox() + for i, data in ipairs(ref_buttonData.textbox) do + --Sets up reference function + local funcName = "textbox"..i + local func = function(_,_,val,sel) click_textbox(i,val,sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = data.label, + alignment = data.alignment, + position = data.pos, + scale = buttonScale, + width = data.width, + height = (data.font_size*data.rows)+24, + font_size = data.font_size, + color = buttonColor, + font_color = buttonFontColor, + value = data.value, + }) + end end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057.ttslua index 46067f58e..901ce543c 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, - font_size=130, color={0,0,0}, font_color={1,1,1} - }) --- self.createButton({ --- label="Setup", click_function="buttonClick_setup", function_owner=self, --- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, --- font_size=250, color={0,0,0}, font_color={1,1,1} --- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-0.6,0.1,2.1}, rotation={0,0,0}, height=220, width=500, + font_size=130, color={0,0,0}, font_color={1,1,1} + }) +-- self.createButton({ +-- label="Setup", click_function="buttonClick_setup", function_owner=self, +-- position={2,0.3,0}, rotation={0,90,0}, height=350, width=800, +-- font_size=250, color={0,0,0}, font_color={1,1,1} +-- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Frozen Tracks 11429d.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Frozen Tracks 11429d.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Frozen Tracks 11429d.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Frozen Tracks 11429d.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Stranded in the Urals 8077a1.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Stranded in the Urals 8077a1.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Stranded in the Urals 8077a1.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag Stranded in the Urals 8077a1.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag The Forgotten Village ddd10b.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag The Forgotten Village ddd10b.ttslua index 4acf9ea11..baa7b8b87 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag The Forgotten Village ddd10b.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Bag The Forgotten Village ddd10b.ttslua @@ -1,273 +1,273 @@ -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function onload(saved_data) - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects() - createSetupActionButtons() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects() - local howManyButtons = 0 - for _, obj in ipairs(getAllObjects()) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1.25 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj) end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=1000, width=1000, - color={0.75,0.25,0.25,0.6}, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons() - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj) - local color = {0,1,0,0.6} - if memoryList[obj.getGUID()] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - memoryList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - self.editButton({index=index, color=color}) - memoryList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) -end - ---Saves selections -function buttonClick_submit() - if next(memoryList) == nil then - broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) - else - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - end -end - ---Resets bag to starting status -function buttonClick_reset() - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local deltaPos = {} - local bounds = obj.getBounds() - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function onload(saved_data) + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects() + createSetupActionButtons() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects() + local howManyButtons = 0 + for _, obj in ipairs(getAllObjects()) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1.25 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj) end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=1000, width=1000, + color={0.75,0.25,0.25,0.6}, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons() + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=1100, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj) + local color = {0,1,0,0.6} + if memoryList[obj.getGUID()] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + memoryList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + self.editButton({index=index, color=color}) + memoryList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) +end + +--Saves selections +function buttonClick_submit() + if next(memoryList) == nil then + broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) + else + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + end +end + +--Resets bag to starting status +function buttonClick_reset() + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={0,0.3,-2}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={0,0.3,-2.8}, rotation={0,180,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={-2,0.3,0}, rotation={0,270,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local deltaPos = {} + local bounds = obj.getBounds() + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end diff --git a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Custom_Tile Winter Winds d54710.ttslua b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Custom_Tile Winter Winds d54710.ttslua index 600057539..65189ba86 100644 --- a/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Custom_Tile Winter Winds d54710.ttslua +++ b/unpacked/Custom_Model_Bag The Side Missions 2d16e1/Custom_Model_Bag Winter Winds 754057/Custom_Tile Winter Winds d54710.ttslua @@ -1,21 +1,21 @@ -name = 'Winter Winds' - -function onLoad() - Global.call('createSetupButtons', {object=self, key=name}) -end - -function easyClick() - Global.call('fillContainer', {object=self, key=name, mode='easy'}) -end - -function normalClick() - Global.call('fillContainer', {object=self, key=name, mode='normal'}) -end - -function hardClick() - Global.call('fillContainer', {object=self, key=name, mode='hard'}) -end - -function expertClick() - Global.call('fillContainer', {object=self, key=name, mode='expert'}) +name = 'Winter Winds' + +function onLoad() + Global.call('createSetupButtons', {object=self, key=name}) +end + +function easyClick() + Global.call('fillContainer', {object=self, key=name, mode='easy'}) +end + +function normalClick() + Global.call('fillContainer', {object=self, key=name, mode='normal'}) +end + +function hardClick() + Global.call('fillContainer', {object=self, key=name, mode='hard'}) +end + +function expertClick() + Global.call('fillContainer', {object=self, key=name, mode='expert'}) end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Weakness decks 750fdd.ttslua b/unpacked/Custom_Model_Bag Weakness decks 750fdd.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Weakness decks 750fdd.ttslua +++ b/unpacked/Custom_Model_Bag Weakness decks 750fdd.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Model_Bag Weakness decks 750fdd/Custom_Model_Bag Weakness decks ceacbf.ttslua b/unpacked/Custom_Model_Bag Weakness decks 750fdd/Custom_Model_Bag Weakness decks ceacbf.ttslua index b25806e6f..f999547e7 100644 --- a/unpacked/Custom_Model_Bag Weakness decks 750fdd/Custom_Model_Bag Weakness decks ceacbf.ttslua +++ b/unpacked/Custom_Model_Bag Weakness decks 750fdd/Custom_Model_Bag Weakness decks ceacbf.ttslua @@ -1,503 +1,503 @@ --- Utility memory bag by Directsun --- Version 2.5.2 --- Fork of Memory Bag 2.0 by MrStump - -function updateSave() - local data_to_save = {["ml"]=memoryList} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function combineMemoryFromBagsWithin() - local bagObjList = self.getObjects() - for _, bagObj in ipairs(bagObjList) do - local data = bagObj.lua_script_state - if data ~= nil then - local j = JSON.decode(data) - if j ~= nil and j.ml ~= nil then - for guid, entry in pairs(j.ml) do - memoryList[guid] = entry - end - end - end - end -end - -function updateMemoryWithMoves() - memoryList = memoryListBackup - --get the first transposed object's coordinates - local obj = getObjectFromGUID(moveGuid) - - -- p1 is where needs to go, p2 is where it was - local refObjPos = memoryList[moveGuid].pos - local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) - local movedRotation = obj.getRotation() - for guid, entry in pairs(memoryList) do - memoryList[guid].pos.x = entry.pos.x - deltaPos.x - memoryList[guid].pos.y = entry.pos.y - deltaPos.y - memoryList[guid].pos.z = entry.pos.z - deltaPos.z - -- memoryList[guid].rot.x = movedRotation.x - -- memoryList[guid].rot.y = movedRotation.y - -- memoryList[guid].rot.z = movedRotation.z - end - - --theList[obj.getGUID()] = { - -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - -- lock=obj.getLock() - --} - moveList = {} -end - -function onload(saved_data) - fresh = true - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - --Set up information off of loaded_data - memoryList = loaded_data.ml - else - --Set up information for if there is no saved saved data - memoryList = {} - end - - moveList = {} - moveGuid = nil - - if next(memoryList) == nil then - createSetupButton() - else - fresh = false - createMemoryActionButtons() - end -end - - ---Beginning Setup - - ---Make setup button -function createSetupButton() - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - ---Triggered by Transpose button -function buttonClick_transpose() - moveGuid = nil - broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - moveList = {} - self.clearButtons() - createButtonsOnAllObjects(true) - createSetupActionButtons(true) -end - ---Triggered by setup button, -function buttonClick_setup() - memoryListBackup = duplicateTable(memoryList) - memoryList = {} - self.clearButtons() - createButtonsOnAllObjects(false) - createSetupActionButtons(false) -end - -function getAllObjectsInMemory() - local objTable = {} - local curObj = {} - - for guid in pairs(memoryListBackup) do - curObj = getObjectFromGUID(guid) - table.insert(objTable, curObj) - end - - return objTable - -- return getAllObjects() -end - ---Creates selection buttons on objects -function createButtonsOnAllObjects(move) - local howManyButtons = 0 - - local objsToHaveButtons = {} - if move == true then - objsToHaveButtons = getAllObjectsInMemory() - else - objsToHaveButtons = getAllObjects() - end - - for _, obj in ipairs(objsToHaveButtons) do - if obj ~= self then - local dummyIndex = howManyButtons - --On a normal bag, the button positions aren't the same size as the bag. - globalScaleFactor = 1 * 1/self.getScale().x - --Super sweet math to set button positions - local selfPos = self.getPosition() - local objPos = obj.getPosition() - local deltaPos = findOffsetDistance(selfPos, objPos, obj) - local objPos = rotateLocalCoordinates(deltaPos, self) - objPos.x = -objPos.x * globalScaleFactor - objPos.y = objPos.y * globalScaleFactor - objPos.z = objPos.z * globalScaleFactor - --Offset rotation of bag - local rot = self.getRotation() - rot.y = -rot.y + 180 - --Create function - local funcName = "selectButton_" .. howManyButtons - local func = function() buttonClick_selection(dummyIndex, obj, move) end - local color = {0.75,0.25,0.25,0.6} - local colorMove = {0,0,1,0.6} - if move == true then - color = colorMove - end - self.setVar(funcName, func) - self.createButton({ - click_function=funcName, function_owner=self, - position=objPos, rotation=rot, height=500, width=500, - color=color, - }) - howManyButtons = howManyButtons + 1 - end - end -end - ---Creates submit and cancel buttons -function createSetupActionButtons(move) - self.createButton({ - label="Cancel", click_function="buttonClick_cancel", function_owner=self, - position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - self.createButton({ - label="Submit", click_function="buttonClick_submit", function_owner=self, - position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - - if move == false then - self.createButton({ - label="Add", click_function="buttonClick_add", function_owner=self, - position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.25,1,0.25} - }) - - if fresh == false then - self.createButton({ - label="Set New", click_function="buttonClick_setNew", function_owner=self, - position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={0.75,0.75,1} - }) - self.createButton({ - label="Remove", click_function="buttonClick_remove", function_owner=self, - position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,0.25,0.25} - }) - end - end - - self.createButton({ - label="Reset", click_function="buttonClick_reset", function_owner=self, - position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) -end - - ---During Setup - - ---Checks or unchecks buttons -function buttonClick_selection(index, obj, move) - local colorMove = {0,0,1,0.6} - local color = {0,1,0,0.6} - - previousGuid = selectedGuid - selectedGuid = obj.getGUID() - - theList = memoryList - if move == true then - theList = moveList - if previousGuid ~= nil and previousGuid ~= selectedGuid then - local prevObj = getObjectFromGUID(previousGuid) - prevObj.highlightOff() - self.editButton({index=previousIndex, color=colorMove}) - theList[previousGuid] = nil - end - previousIndex = index - end - - if theList[selectedGuid] == nil then - self.editButton({index=index, color=color}) - --Adding pos/rot to memory table - local pos, rot = obj.getPosition(), obj.getRotation() - --I need to add it like this or it won't save due to indexing issue - theList[obj.getGUID()] = { - pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, - rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, - lock=obj.getLock() - } - obj.highlightOn({0,1,0}) - else - color = {0.75,0.25,0.25,0.6} - if move == true then - color = colorMove - end - self.editButton({index=index, color=color}) - theList[obj.getGUID()] = nil - obj.highlightOff() - end -end - ---Cancels selection process -function buttonClick_cancel() - memoryList = memoryListBackup - moveList = {} - self.clearButtons() - if next(memoryList) == nil then - createSetupButton() - else - createMemoryActionButtons() - end - removeAllHighlights() - broadcastToAll("Selection Canceled", {1,1,1}) - moveGuid = nil -end - ---Saves selections -function buttonClick_submit() - fresh = false - if next(moveList) ~= nil then - for guid in pairs(moveList) do - moveGuid = guid - end - if memoryListBackup[moveGuid] == nil then - broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) - else - broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(moveList) do - moveGuid = guid - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - updateMemoryWithMoves() - updateSave() - buttonClick_place() - end - elseif next(memoryList) == nil and moveGuid == nil then - memoryList = memoryListBackup - broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) - end - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() - moveGuid = nil -end - -function combineTables(first_table, second_table) - for k,v in pairs(second_table) do first_table[k] = v end -end - -function buttonClick_add() - fresh = false - combineTables(memoryList, memoryListBackup) - broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) - combineMemoryFromBagsWithin() - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - updateSave() -end - -function buttonClick_remove() - broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for guid in pairs(memoryList) do - count = count + 1 - memoryListBackup[guid] = nil - local obj = getObjectFromGUID(guid) - if obj ~= nil then obj.highlightOff() end - end - broadcastToAll(count.." Objects Removed", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - -function buttonClick_setNew() - broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) - self.clearButtons() - createMemoryActionButtons() - local count = 0 - for _, obj in ipairs(getAllObjects()) do - guid = obj.guid - if memoryListBackup[guid] ~= nil then - count = count + 1 - memoryListBackup[guid].pos = obj.getPosition() - memoryListBackup[guid].rot = obj.getRotation() - memoryListBackup[guid].lock = obj.getLock() - end - end - broadcastToAll(count.." Objects Saved", {1,1,1}) - memoryList = memoryListBackup - updateSave() -end - ---Resets bag to starting status -function buttonClick_reset() - fresh = true - memoryList = {} - self.clearButtons() - createSetupButton() - removeAllHighlights() - broadcastToAll("Tool Reset", {1,1,1}) - updateSave() -end - - ---After Setup - - ---Creates recall and place buttons -function createMemoryActionButtons() - self.createButton({ - label="Place", click_function="buttonClick_place", function_owner=self, - position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Recall", click_function="buttonClick_recall", function_owner=self, - position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) - self.createButton({ - label="Setup", click_function="buttonClick_setup", function_owner=self, - position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, - font_size=250, color={0,0,0}, font_color={1,1,1} - }) ---- self.createButton({ ---- label="Move", click_function="buttonClick_transpose", function_owner=self, ---- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, ---- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} ---- }) -end - ---Sends objects from bag/table to their saved position/rotation -function buttonClick_place() - local bagObjList = self.getObjects() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - --If obj is out on the table, move it to the saved pos/rot - if obj ~= nil then - obj.setPositionSmooth(entry.pos) - obj.setRotationSmooth(entry.rot) - obj.setLock(entry.lock) - else - --If obj is inside of the bag - for _, bagObj in ipairs(bagObjList) do - if bagObj.guid == guid then - local item = self.takeObject({ - guid=guid, position=entry.pos, rotation=entry.rot, smooth=false - }) - item.setLock(entry.lock) - break - end - end - end - end - broadcastToAll("Objects Placed", {1,1,1}) -end - ---Recalls objects to bag from table -function buttonClick_recall() - for guid, entry in pairs(memoryList) do - local obj = getObjectFromGUID(guid) - if obj ~= nil then self.putObject(obj) end - end - broadcastToAll("Objects Recalled", {1,1,1}) -end - - ---Utility functions - - ---Find delta (difference) between 2 x/y/z coordinates -function findOffsetDistance(p1, p2, obj) - local yOffset = 0 - if obj ~= nil then - local bounds = obj.getBounds() - yOffset = (bounds.size.y - bounds.offset.y) - end - local deltaPos = {} - deltaPos.x = (p2.x-p1.x) - deltaPos.y = (p2.y-p1.y) + yOffset - deltaPos.z = (p2.z-p1.z) - return deltaPos -end - ---Used to rotate a set of coordinates by an angle -function rotateLocalCoordinates(desiredPos, obj) - local objPos, objRot = obj.getPosition(), obj.getRotation() - local angle = math.rad(objRot.y) - local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) - local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) - --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} - return {x=x, y=desiredPos.y, z=z} -end - -function rotateMyCoordinates(desiredPos, obj) - local angle = math.rad(obj.getRotation().y) - local x = desiredPos.x * math.sin(angle) - local z = desiredPos.z * math.cos(angle) - return {x=x, y=desiredPos.y, z=z} -end - ---Coroutine delay, in seconds -function wait(time) - local start = os.time() - repeat coroutine.yield(0) until os.time() > start + time -end - ---Duplicates a table (needed to prevent it making reference to the same objects) -function duplicateTable(oldTable) - local newTable = {} - for k, v in pairs(oldTable) do - newTable[k] = v - end - return newTable -end - ---Moves scripted highlight from all objects -function removeAllHighlights() - for _, obj in ipairs(getAllObjects()) do - obj.highlightOff() - end -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult +-- Utility memory bag by Directsun +-- Version 2.5.2 +-- Fork of Memory Bag 2.0 by MrStump + +function updateSave() + local data_to_save = {["ml"]=memoryList} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function combineMemoryFromBagsWithin() + local bagObjList = self.getObjects() + for _, bagObj in ipairs(bagObjList) do + local data = bagObj.lua_script_state + if data ~= nil then + local j = JSON.decode(data) + if j ~= nil and j.ml ~= nil then + for guid, entry in pairs(j.ml) do + memoryList[guid] = entry + end + end + end + end +end + +function updateMemoryWithMoves() + memoryList = memoryListBackup + --get the first transposed object's coordinates + local obj = getObjectFromGUID(moveGuid) + + -- p1 is where needs to go, p2 is where it was + local refObjPos = memoryList[moveGuid].pos + local deltaPos = findOffsetDistance(obj.getPosition(), refObjPos, nil) + local movedRotation = obj.getRotation() + for guid, entry in pairs(memoryList) do + memoryList[guid].pos.x = entry.pos.x - deltaPos.x + memoryList[guid].pos.y = entry.pos.y - deltaPos.y + memoryList[guid].pos.z = entry.pos.z - deltaPos.z + -- memoryList[guid].rot.x = movedRotation.x + -- memoryList[guid].rot.y = movedRotation.y + -- memoryList[guid].rot.z = movedRotation.z + end + + --theList[obj.getGUID()] = { + -- pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + -- rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + -- lock=obj.getLock() + --} + moveList = {} +end + +function onload(saved_data) + fresh = true + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + --Set up information off of loaded_data + memoryList = loaded_data.ml + else + --Set up information for if there is no saved saved data + memoryList = {} + end + + moveList = {} + moveGuid = nil + + if next(memoryList) == nil then + createSetupButton() + else + fresh = false + createMemoryActionButtons() + end +end + + +--Beginning Setup + + +--Make setup button +function createSetupButton() + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + +--Triggered by Transpose button +function buttonClick_transpose() + moveGuid = nil + broadcastToAll("Select one object and move it- all objects will move relative to the new location", {0.75, 0.75, 1}) + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + moveList = {} + self.clearButtons() + createButtonsOnAllObjects(true) + createSetupActionButtons(true) +end + +--Triggered by setup button, +function buttonClick_setup() + memoryListBackup = duplicateTable(memoryList) + memoryList = {} + self.clearButtons() + createButtonsOnAllObjects(false) + createSetupActionButtons(false) +end + +function getAllObjectsInMemory() + local objTable = {} + local curObj = {} + + for guid in pairs(memoryListBackup) do + curObj = getObjectFromGUID(guid) + table.insert(objTable, curObj) + end + + return objTable + -- return getAllObjects() +end + +--Creates selection buttons on objects +function createButtonsOnAllObjects(move) + local howManyButtons = 0 + + local objsToHaveButtons = {} + if move == true then + objsToHaveButtons = getAllObjectsInMemory() + else + objsToHaveButtons = getAllObjects() + end + + for _, obj in ipairs(objsToHaveButtons) do + if obj ~= self then + local dummyIndex = howManyButtons + --On a normal bag, the button positions aren't the same size as the bag. + globalScaleFactor = 1 * 1/self.getScale().x + --Super sweet math to set button positions + local selfPos = self.getPosition() + local objPos = obj.getPosition() + local deltaPos = findOffsetDistance(selfPos, objPos, obj) + local objPos = rotateLocalCoordinates(deltaPos, self) + objPos.x = -objPos.x * globalScaleFactor + objPos.y = objPos.y * globalScaleFactor + objPos.z = objPos.z * globalScaleFactor + --Offset rotation of bag + local rot = self.getRotation() + rot.y = -rot.y + 180 + --Create function + local funcName = "selectButton_" .. howManyButtons + local func = function() buttonClick_selection(dummyIndex, obj, move) end + local color = {0.75,0.25,0.25,0.6} + local colorMove = {0,0,1,0.6} + if move == true then + color = colorMove + end + self.setVar(funcName, func) + self.createButton({ + click_function=funcName, function_owner=self, + position=objPos, rotation=rot, height=500, width=500, + color=color, + }) + howManyButtons = howManyButtons + 1 + end + end +end + +--Creates submit and cancel buttons +function createSetupActionButtons(move) + self.createButton({ + label="Cancel", click_function="buttonClick_cancel", function_owner=self, + position={-1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + self.createButton({ + label="Submit", click_function="buttonClick_submit", function_owner=self, + position={-1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + + if move == false then + self.createButton({ + label="Add", click_function="buttonClick_add", function_owner=self, + position={1,0.1,-2.1}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.25,1,0.25} + }) + + if fresh == false then + self.createButton({ + label="Set New", click_function="buttonClick_setNew", function_owner=self, + position={1,0.1,-3.7}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={0.75,0.75,1} + }) + self.createButton({ + label="Remove", click_function="buttonClick_remove", function_owner=self, + position={1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,0.25,0.25} + }) + end + end + + self.createButton({ + label="Reset", click_function="buttonClick_reset", function_owner=self, + position={-1,0.1,-2.9}, rotation={0,0,0}, height=350, width=900, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +end + + +--During Setup + + +--Checks or unchecks buttons +function buttonClick_selection(index, obj, move) + local colorMove = {0,0,1,0.6} + local color = {0,1,0,0.6} + + previousGuid = selectedGuid + selectedGuid = obj.getGUID() + + theList = memoryList + if move == true then + theList = moveList + if previousGuid ~= nil and previousGuid ~= selectedGuid then + local prevObj = getObjectFromGUID(previousGuid) + prevObj.highlightOff() + self.editButton({index=previousIndex, color=colorMove}) + theList[previousGuid] = nil + end + previousIndex = index + end + + if theList[selectedGuid] == nil then + self.editButton({index=index, color=color}) + --Adding pos/rot to memory table + local pos, rot = obj.getPosition(), obj.getRotation() + --I need to add it like this or it won't save due to indexing issue + theList[obj.getGUID()] = { + pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, + rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, + lock=obj.getLock() + } + obj.highlightOn({0,1,0}) + else + color = {0.75,0.25,0.25,0.6} + if move == true then + color = colorMove + end + self.editButton({index=index, color=color}) + theList[obj.getGUID()] = nil + obj.highlightOff() + end +end + +--Cancels selection process +function buttonClick_cancel() + memoryList = memoryListBackup + moveList = {} + self.clearButtons() + if next(memoryList) == nil then + createSetupButton() + else + createMemoryActionButtons() + end + removeAllHighlights() + broadcastToAll("Selection Canceled", {1,1,1}) + moveGuid = nil +end + +--Saves selections +function buttonClick_submit() + fresh = false + if next(moveList) ~= nil then + for guid in pairs(moveList) do + moveGuid = guid + end + if memoryListBackup[moveGuid] == nil then + broadcastToAll("Item selected for moving is not already in memory", {1, 0.25, 0.25}) + else + broadcastToAll("Moving all items in memory relative to new objects position!", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(moveList) do + moveGuid = guid + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + updateMemoryWithMoves() + updateSave() + buttonClick_place() + end + elseif next(memoryList) == nil and moveGuid == nil then + memoryList = memoryListBackup + broadcastToAll("No selections made.", {0.75, 0.25, 0.25}) + end + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() + moveGuid = nil +end + +function combineTables(first_table, second_table) + for k,v in pairs(second_table) do first_table[k] = v end +end + +function buttonClick_add() + fresh = false + combineTables(memoryList, memoryListBackup) + broadcastToAll("Adding internal bags and selections to existing memory", {0.25, 0.75, 0.25}) + combineMemoryFromBagsWithin() + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + updateSave() +end + +function buttonClick_remove() + broadcastToAll("Removing Selected Entries From Memory", {1.0, 0.25, 0.25}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for guid in pairs(memoryList) do + count = count + 1 + memoryListBackup[guid] = nil + local obj = getObjectFromGUID(guid) + if obj ~= nil then obj.highlightOff() end + end + broadcastToAll(count.." Objects Removed", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +function buttonClick_setNew() + broadcastToAll("Setting new position relative to items in memory", {0.75, 0.75, 1}) + self.clearButtons() + createMemoryActionButtons() + local count = 0 + for _, obj in ipairs(getAllObjects()) do + guid = obj.guid + if memoryListBackup[guid] ~= nil then + count = count + 1 + memoryListBackup[guid].pos = obj.getPosition() + memoryListBackup[guid].rot = obj.getRotation() + memoryListBackup[guid].lock = obj.getLock() + end + end + broadcastToAll(count.." Objects Saved", {1,1,1}) + memoryList = memoryListBackup + updateSave() +end + +--Resets bag to starting status +function buttonClick_reset() + fresh = true + memoryList = {} + self.clearButtons() + createSetupButton() + removeAllHighlights() + broadcastToAll("Tool Reset", {1,1,1}) + updateSave() +end + + +--After Setup + + +--Creates recall and place buttons +function createMemoryActionButtons() + self.createButton({ + label="Place", click_function="buttonClick_place", function_owner=self, + position={1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Recall", click_function="buttonClick_recall", function_owner=self, + position={-1,0.1,2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) + self.createButton({ + label="Setup", click_function="buttonClick_setup", function_owner=self, + position={0,0.1,-2.1}, rotation={0,0,0}, height=350, width=800, + font_size=250, color={0,0,0}, font_color={1,1,1} + }) +--- self.createButton({ +--- label="Move", click_function="buttonClick_transpose", function_owner=self, +--- position={-2.8,0.3,0}, rotation={0,0,0}, height=350, width=800, +--- font_size=250, color={0,0,0}, font_color={0.75,0.75,1} +--- }) +end + +--Sends objects from bag/table to their saved position/rotation +function buttonClick_place() + local bagObjList = self.getObjects() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + --If obj is out on the table, move it to the saved pos/rot + if obj ~= nil then + obj.setPositionSmooth(entry.pos) + obj.setRotationSmooth(entry.rot) + obj.setLock(entry.lock) + else + --If obj is inside of the bag + for _, bagObj in ipairs(bagObjList) do + if bagObj.guid == guid then + local item = self.takeObject({ + guid=guid, position=entry.pos, rotation=entry.rot, smooth=false + }) + item.setLock(entry.lock) + break + end + end + end + end + broadcastToAll("Objects Placed", {1,1,1}) +end + +--Recalls objects to bag from table +function buttonClick_recall() + for guid, entry in pairs(memoryList) do + local obj = getObjectFromGUID(guid) + if obj ~= nil then self.putObject(obj) end + end + broadcastToAll("Objects Recalled", {1,1,1}) +end + + +--Utility functions + + +--Find delta (difference) between 2 x/y/z coordinates +function findOffsetDistance(p1, p2, obj) + local yOffset = 0 + if obj ~= nil then + local bounds = obj.getBounds() + yOffset = (bounds.size.y - bounds.offset.y) + end + local deltaPos = {} + deltaPos.x = (p2.x-p1.x) + deltaPos.y = (p2.y-p1.y) + yOffset + deltaPos.z = (p2.z-p1.z) + return deltaPos +end + +--Used to rotate a set of coordinates by an angle +function rotateLocalCoordinates(desiredPos, obj) + local objPos, objRot = obj.getPosition(), obj.getRotation() + local angle = math.rad(objRot.y) + local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) + local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) + --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} + return {x=x, y=desiredPos.y, z=z} +end + +function rotateMyCoordinates(desiredPos, obj) + local angle = math.rad(obj.getRotation().y) + local x = desiredPos.x * math.sin(angle) + local z = desiredPos.z * math.cos(angle) + return {x=x, y=desiredPos.y, z=z} +end + +--Coroutine delay, in seconds +function wait(time) + local start = os.time() + repeat coroutine.yield(0) until os.time() > start + time +end + +--Duplicates a table (needed to prevent it making reference to the same objects) +function duplicateTable(oldTable) + local newTable = {} + for k, v in pairs(oldTable) do + newTable[k] = v + end + return newTable +end + +--Moves scripted highlight from all objects +function removeAllHighlights() + for _, obj in ipairs(getAllObjects()) do + obj.highlightOff() + end +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult end \ No newline at end of file diff --git a/unpacked/Custom_Tile Data Helper 708279.ttslua b/unpacked/Custom_Tile Data Helper 708279.ttslua index 056db840a..c58a9cb51 100644 --- a/unpacked/Custom_Tile Data Helper 708279.ttslua +++ b/unpacked/Custom_Tile Data Helper 708279.ttslua @@ -1,1680 +1,1680 @@ - -- set true to enable debug logging - DEBUG = false - - function log(message) - if DEBUG then - print(message) - end - end - - --[[ - Known locations and clues. We check this to determine if we should - atttempt to spawn clues, first we look for _ and if - we find nothing we look for - format is [location_guid -> clueCount] - ]] - LOCATIONS_DATA_JSON = [[ - { - "Study": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Study_670914": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Attic_377b20": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Attic": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Cellar_5d3bcc": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Cellar": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Bathroom": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Bedroom": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Far Above Your House": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Deep Below Your House": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Northside_86faac": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Northside": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Graveyard": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Miskatonic University_cedb0a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Miskatonic University": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Downtown_1aa7cb": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Downtown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "St. Mary's Hospital": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Easttown_88245c": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Easttown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Southside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Rivertown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Your House_377b20": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Your House_b28633": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Ritual Site": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Arkham Woods_e8e04b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Arkham Woods": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "New Orleans_5ab18a": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "New Orleans": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Riverside_ab9d69": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Riverside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Wilderness_3c5ea8": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Wilderness": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Unhallowed Land_552a1d": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Unhallowed Land": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Flooded Square": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Streets of Venice": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Rialto Bridge": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Venetian Garden": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Guardian": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Canal-side": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Accademia Bridge": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Bridge of Sighs": {"type": "fixed", "value": 2, "clueSide": "back"}, - - "Warren Observatory": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Science Building": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Orne Library": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Administration Building": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Student Union": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Humanities Building": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Dormitories": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - "Faculty Offices": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Faculty Offices_1c567d": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - - "La Bella Luna": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Back Hall Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Museum Entrance": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Security Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Security Office_fcb3e4": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Administration Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Administration Office_d2eb25": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Exhibit Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Exhibit Hall_563240": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Exhibit Hall_f3ffb6": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Exhibit Hall_0b0c58": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Exhibit Hall_2d87e6": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Exhibit Hall_da02ea": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - - "Train Car": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Train Car_f3f902": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Train Car_905f69": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Train Car_a3a321": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Train Car_464528": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Train Car_3cfca4": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Train Car_64ffb0": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Train Car_0fb5f0": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - "Engine Car": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "House in the Reeds": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Osborn's General Store": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Congregational Church": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Bishop's Brook": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Burned Ruins": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Schoolhouse": {"type": "fixed", "value": 1, "clueSide": "back"}, - - "Dunwich Village": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Dunwich Village_ac4427": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Cold Spring Glen": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Cold Spring Glen_e58475": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Ten-Acre Meadow": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Ten-Acre Meadow_05b0dd": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Blasted Heath": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Blasted Heath_995fe7": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Whateley Ruins": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Devil's Hop Yard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Devil's Hop Yard_f7dd31": {"type": "fixed", "value": 2, "clueSide": "back"}, - - "Base of the Hill": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Base of the Hill_80236e": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Ascending Path": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Ascending Path_d3ae26": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Sentinel Peak": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Diverging Path": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Diverging Path_7239aa": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Altered Path": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "The Edge of the Universe": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Tear Through Time": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Prismatic Cascade": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Towering Luminosity": {"type": "fixed", "value": 4, "clueSide": "front"}, - "Tear Through Space": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Endless Bridge": {"type": "fixed", "value": 2, "clueSide": "front"}, - "Dimensional Doorway": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Steps of Y'hagharl": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Unstable Vortex": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Indecipherable Stairs": {"type": "fixed", "value": 1, "clueSide": "front"}, - - "Backstage Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Backstage Doorway_0797a9": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Lobby Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Lobby Doorway_7605cf": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Lobby": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Backstage": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Balcony": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Foyer": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Historical Society": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Historical Society_40f79d": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Historical Society_b352f8": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Historical Society_0cf5d5": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Historical Society_abc0cb": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Historical Society_ab6a72": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Hidden Library": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - - "Patient Confinement": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Asylum Halls": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Asylum Halls_f99530": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Asylum Halls_576595": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Infirmary": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Basement Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Yard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Garden": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Kitchen": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Mess Hall": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Grand Guignol": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Montmartre": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Montmartre_cbaacc": {"type": "perPlayer", "value": 0, "clueSide": "front"}, - "Montparnasse": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Notre-Dame": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Gare d'Orsay": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Opéra Garnier": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Canal Saint-Martin": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Le Marais": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Gardens of Luxembourg": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Père Lachaise Cemetery": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Catacombs": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Catacombs_29170f": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Catacombs_f1237c": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Catacombs_c3151e": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Catacombs_14b1cb": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Catacombs_81920c": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Catacombs_c14c8b": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Catacombs_ea2a55": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Catacombs_8bcab3": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Catacombs_7c7f4a": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Catacombs_80cf41": {"type": "fixed", "value": 0, "clueSide": "back"}, - - "Abbey Church": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Porte de l'Avancée": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Grand Rue": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Cloister": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Knight's Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Chœur Gothique": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Outer Wall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Outer Wall_014bd6": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "North Tower": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "North Tower_69eae5": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Chapel of St. Aubert": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - "Chapel of St. Aubert_e75ba8": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Abbey Tower": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - "Abbey Tower_2f3d21": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Shores of Hali": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Dark Spires": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Palace of the King": {"type": "perPlayer", "value": 3, "clueSide": "front"}, - "Palace of the King_60d758": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Ruins of Carcosa": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Dim Streets": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Depths of Demhe": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Bleak Plains": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Recesses of Your Own Mind": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "The Throne Room": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Stage of the Ward Theatre": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "Serpent’s Haven": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Ruins of Eztli": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Rope Bridge": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Overgrown Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "River Canyon": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Path of Thorns": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Temple of the Fang": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Circuitous Trail": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Riverside Temple": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Waterfall": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Trail of the Dead": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Cloud Forest": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "Chamber of Time": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Ancient Hall": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Ancient Hall_b9acb8": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Grand Chamber": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Entryway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Underground Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Burial Pit": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Secret Passage": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Snake Pit": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Throne Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Mosaic Chamber": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Tomb of the Ancients": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Town Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Curiositie Shoppe": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "At the Station": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "At the Station_e0833c": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Missing Persons": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "The Relic is Missing!": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Trial of the Huntress": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Search for the Meaning": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Seeking Trouble": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Seeking Trouble_42f93b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - - "Sacred Woods": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Chapultepec Hill": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Chapultepec Hill_baec21": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Canals of Tenochtitlán": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Lake Xochimilco": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Lake Xochimilco_59bf7d": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Templo Mayor": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Templo Mayor_fb0083": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Temples of Tenochtitlán": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Temples of Tenochtitlán_80cef8": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Mouth of K'n-yan_38a3e5": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Stone Altar": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Time-Wracked Woods": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Vast Passages": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Perilous Gulch": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Dark Hollow": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Hall of Idolatry": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Crystal Pillars": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Ruins of K’n-yan": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Chthonian Depths": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Subterranean Swamp": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Treacherous Descent": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Interview Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Interview Room_b1861c": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Halls of Pnakotus": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Deconstruction Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Towers of Pnakotus": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Laboratory of the Great Race": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Yithian Orrery": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Great Library": {"type": "fixed", "value": 4, "clueSide": "back"}, - "Cyclopean Vaults": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Alien Conservatory": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "City of the Serpents": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Bridge over N'kai": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Abandoned Site": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Caverns of Yoth": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Hall of Heresy": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Bright Canyon": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Forked Path": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - - "Nexus of N'kai": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "A Pocket in Time": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "City of the Unseen": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Valusia": {"type": "fixed", "value": 2, "clueSide": "front"}, - "Great Hall of Celeano": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Buenos Aires": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Ultima Thule": {"type": "fixed", "value": 2, "clueSide": "front"}, - - "Shores of R’lyeh": {"type": "fixed", "value": 2, "clueSide": "front"}, - "Atlantis": {"type": "fixed", "value": 2, "clueSide": "front"}, - "Pnakotus": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Ruins of New York": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Yuggoth": {"type": "fixed", "value": 3, "clueSide": "front"}, - "Mu": {"type": "fixed", "value": 4, "clueSide": "front"}, - "Plateau of Leng_0ab6ff": {"type": "fixed", "value": 1, "clueSide": "front"}, - - "Billiards Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Billiards Room_33990b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Trophy Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Trophy Room_e9160a": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Master Bedroom": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Balcony_1b5483": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Office_a1bd9a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Witch-Haunted Woods_1539ea": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Witch-Haunted Woods": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Witch-Haunted Woods_d3f8c3": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Witch-Haunted Woods_eca18e": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Paths into Twilight": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - - "The Imperial Entrance": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Dark Stairwell": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Stairway": {"type": "fixed", "value": 1, "clueSide": "back"}, - "The Balcony": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Back Booths": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Lobby": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Backroom Door": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Backroom Door_ed439d": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Dining Area": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "The Dance Floor": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Gateway to the East": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Back Alley": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Mingzhu Laundry": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Dragon's Den": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "The Phoenix's Nest": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Golden Temple of the Heavens": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Flea Market": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Zihao's House of Fighting Arts": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Daiyu's Tea Garden": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Moldy Halls": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Decrepit Door": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Walter Gilman's Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Unknown Places_b538f8": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Unknown Places_7bea34": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Unknown Places": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Unknown Places_9a471d": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Unknown Places_0ac3ea": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Strange Geometry": {"type": "fixed", "value": 1, "clueSide": "front"}, - "Site of the Sacrifice": {"type": "perPlayer", "value": 3, "clueSide": "back"}, - - "Hangman's Brook": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Abandoned Chapel": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Haunted Fields": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Lobby_1c2dfe": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Lobby_bcd556": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Lodge Gates_fa6a29": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Lodge Gates": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Lodge Cellar": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Lodge Cellar_8ea4fd": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Lounge": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Vault": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Inner Sanctum": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Library": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Library_47ccbc": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Sanctum Doorway": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Sanctum Doorway_4da6c3": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "The Geist-Trap": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Forbidding Shore": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Unvisited Isle": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Rivertown_92ee68": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Rivertown_db4b20": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Southside_c898a0": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Southside_e7f5fa": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Silver Twilight Lodge": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Silver Twilight Lodge_17e686": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Hangman's Hill": {"type": "fixed", "value": 0, "clueSide": "back"}, - "Hangman's Hill_5f4d8a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Cosmic Ingress": {"type": "fixed", "value": 3, "clueSide": "back"}, - "Cosmos": {"type": "fixed", "value": 1, "clueSide": "back"}, - "Cosmos_a89dbf": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Cosmos_1a0ad2": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Cosmos_30fc53": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Cosmos_8f3e16": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Cosmos_4e8ae3": {"type": "fixed", "value": 2, "clueSide": "back"}, - "Cosmos_a8d84d": {"type": "fixed", "value": 4, "clueSide": "back"}, - "Cosmos_7a3ece": {"type": "fixed", "value": 6, "clueSide": "back"}, - "Cosmos_311eb1": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Seventy Steps": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Seven Hundred Steps": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Base of the Steps": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Enchanted Woods": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Stairwell": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Basement Door_42fa87": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Basement Door": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Waiting Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Emergency Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Experimental Therapies Ward": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Records Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Foyer_9a9f9a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Room 245": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Hotel Roof": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Office_b3ed47": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Room 212": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Basement": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Second Floor Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Room 225": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Restaurant": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Suite Balcony": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Ulthar": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Dylath-Leen": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Mt. Ngranek": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Baharna": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Zulan-Thek": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Sarnath": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "City-Which-Appears-On-No-Map": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Celephaïs": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Nameless Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Kadatheron": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Ilek-Vad": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Ruins of Ib": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Temple of Unattainable Desires": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Hazuth-Kleg": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Serannian": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Mysterious Stairs": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Mysterious Stairs_df1a40": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Attic_10faf9": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Unmarked Tomb": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Upstairs Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Front Porch": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Downstairs Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Downstairs Doorway_c93906": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Burial Ground": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Temple of the Moon Lizard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "City of the Moon-Beasts": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Moon-Forest": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Dark Crater": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Caverns Beneath the Moon": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Black Core": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Light Side of the Moon": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "City of Gugs": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Vaults of Zin": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Plain of the Ghouls": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Sea of Bones": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Vale of Pnath": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Crag of the Ghouls": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Sea of Pitch": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Plateau of Leng": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Cold Wastes": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Monastery of Leng": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Onyx Gates": {"type": "fixed", "value": 12, "clueSide": "back"}, - "Forsaken Tower": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "The Crater": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Quarantine Zone": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Quarantine Zone_5f2a9b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Quarantine Zone_4a8e9c": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Quarantine Zone_5193e9": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Quarantine Zone_b3a920": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "The Great Web": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Great Web_39ace3": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "The Great Web_727790": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "The Great Web_5c5ec4": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "The Great Web_361fd7": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "The Great Web_dfdc8c": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Expedition Camp": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Desert Oasis": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Untouched Vault": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Sands of Dashur": {"type": "perPlayer", "value": 0, "clueSide": "front"}, - "Sandswept Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Nile River": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Faceless Sphinx": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Dunes of the Sahara": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Streets of Cairo": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Cairo Bazaar": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Temple Courtyard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Museum of Egyptian Antiquities": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Outskirts of Cairo": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - - "Eldritch Gate": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Mist-Filled Caverns": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Stairway to Sarkomand": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Tunnels under Ngranek": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "The Great Abyss": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "A Dream Betwixt": {"type": "perPlayer", "value": 0, "clueSide": "front"}, - - "Velma's Doghouse": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Barkham City Pound": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Barkham Asylum": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Beasttown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Tailside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Slobbertown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Snoutside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Muttskatonic University": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Boneyard": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "St. Mary's Animal Hospital": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Unfamiliar Chamber": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Tidal Tunnel": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Tidal Tunnel_0f20fc": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Tidal Tunnel_d5566b": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Tidal Tunnel_dc9eb7": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - "Tidal Tunnel_513d82": {"type": "perPlayer", "value": 0, "clueSide": "back"}, - - "First National Grocery": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Marsh Refinery": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Innsmouth Square": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Innsmouth Harbour": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Fish Street Bridge_b6b9b7": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Gilman House": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Little Bookshop": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - - "Innsmouth Jail_f63738": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "New Church Green_d1ef9c": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Sawbone Alley_899c2c": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "The House on Water Street_e4f53a": {"type": "perPlayer", "value": 2, "clueSide": "front"}, - "Shoreward Slums_24e42d": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - "Esoteric Order of Dagon_28c301": {"type": "perPlayer", "value": 1, "clueSide": "front"}, - - "Esoteric Order of Dagon_ef8cef": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "New Church Green_921a9b": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Marsh Refinery_44c342": {"type": "fixed", "value": 1, "clueSide": "back"}, - "The House on Water Street_104e07": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "The Little Bookshop_a17a82": {"type": "fixed", "value": 1, "clueSide": "back"}, - "First National Grocery_9ae75c": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Fish Street Bridge_a358fc": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Innsmouth Harbour_30b2c0": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Sawbone Alley_e58cff": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Gilman House_e589b8": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "Innsmouth Jail_755fc0": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Shoreward Slums_c0d0df": {"type": "perPlayer", "value": 1, "clueSide": "back"}, - "Desolate Coastline": {"type": "fixed", "value": 1, "clueSide": "back"}, - - "XXXX": {"type": "perPlayer", "value": 2, "clueSide": "back"}, - "xxx": {"type": "perPlayer", "value": 2, "clueSide": "back"} - } - ]] - --[[ - Player cards with token counts and types - ]] - PLAYER_CARD_DATA_JSON = [[ - { - "Flashlight": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Shrivelling": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Shrivelling (3)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Grotesque Statue (4)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Forbidden Knowledge": { - "tokenType": "resource", - "tokenCount": 4 - }, - ".45 Automatic": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Shotgun (4)": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Liquid Courage": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Song of the Dead (2)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Cover Up": { - "tokenType": "clue", - "tokenCount": 3 - }, - "Roland's .38 Special": { - "tokenType": "resource", - "tokenCount": 4 - }, - "First Aid": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Scrying": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".41 Derringer": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Painkillers": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Smoking Pipe": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Clarity of Mind": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Rite of Seeking": { - "tokenType": "resource", - "tokenCount": 3 - }, - "M1918 BAR (4)": { - "tokenType": "resource", - "tokenCount": 8 - }, - "Ornate Bow (3)": { - "tokenType": "resource", - "tokenCount": 1 - }, - ".41 Derringer (2)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Suggestion (4)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Chicago Typewriter (4)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Lupara (3)": { - "tokenType": "resource", - "tokenCount": 2 - }, - "First Aid (3)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Springfield M1903 (4)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Springfield M1903 (4) (Taboo)": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".32 Colt": { - "tokenType": "resource", - "tokenCount": 6 - }, - "Venturer": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Lockpicks (1)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Finn's Trusty .38": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".45 Automatic (2)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Lightning Gun (5)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Strange Solution (4)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Strange Solution (4):Acidic Ichor": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Strange Solution (4):Empowering Elixir": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Arcane Insight (4)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Archaic Glyphs (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "In the Know (1)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Rite of Seeking (4)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Alchemical Transmutation": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Scrying (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Shrivelling (5)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Mists of R'lyeh": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Mists of R'lyeh (4)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Colt Vest Pocket": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Old Hunting Rifle (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Thermos": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Feed the Mind (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Seal of the Seventh Sign (5)": { - "tokenType": "resource", - "tokenCount": 7 - }, - "Flamethrower (5)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Flamethrower (5) (Taboo)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Pnakotic Manuscripts (5)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Kerosene (1)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Shards of the Void (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Try and Try Again (1)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Arcane Initiate": { - "tokenType": "doom", - "tokenCount": 1 - }, - "Detective's Colt 1911s": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Extra Ammunition (1)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Rite of Seeking (2)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Arcane Initiate (3)": { - "tokenType": "doom", - "tokenCount": 1 - }, - "Clarity of Mind (3)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Fingerprint Kit": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Truth from Fiction": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Enchanted Blade": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Tennessee Sour Mash": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Scroll of Secrets": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Scroll of Secrets (Taboo)": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".45 Thompson": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Mr. \"Rook\"": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Mr. \"Rook\" (Taboo)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Scroll of Secrets (3):Seeker": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Scroll of Secrets (3) (Taboo):Seeker": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Scroll of Secrets (3):Mystic": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Scroll of Secrets (3) (Taboo):Mystic": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Enchanted Blade (3):Guardian": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Enchanted Blade (3):Mystic": { - "tokenType": "resource", - "tokenCount": 4 - }, - ".45 Thompson (3)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Esoteric Atlas (1)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Tennessee Sour Mash (3):Rogue": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Tennessee Sour Mash (3):Survivor": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Mk 1 Grenades (4)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Dayana Esperence (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Pendant of the Queen": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".32 Colt (2)": { - "tokenType": "resource", - "tokenCount": 6 - }, - "Alchemical Transmutation (2)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Suggestion (1)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Gate Box": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Tony's .38 Long Colt": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Gregory Gry": { - "tokenType": "resource", - "tokenCount": 9 - }, - "Scroll of Prophecies": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Healing Words": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Otherworld Codex (2)": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".35 Winchester": { - "tokenType": "resource", - "tokenCount": 5 - }, - ".35 Winchester (Taboo)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Old Book of Lore (3)": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Sawed-Off Shotgun (5)": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Mind's Eye (2)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Colt Vest Pocket (2)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Mists of R'lyeh (2)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "The Chthonian Stone (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Flesh Ward": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Physical Training (4)": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Encyclopedia": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Feed the Mind": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Forbidden Tome": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Esoteric Atlas (2)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "The Necronomicon (5)": { - "tokenType": "resource", - "tokenCount": 6 - }, - "The Necronomicon (5) (Taboo)": { - "tokenType": "resource", - "tokenCount": 6 - }, - "Mauser C96": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Liquid Courage (1)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Mauser C96 (2)": { - "tokenType": "resource", - "tokenCount": 5 - }, - "Beretta M1918 (4)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Scrying Mirror": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Azure Flame": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Clairvoyance": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Ineffable Truth": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Grotesque Statue (2)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Azure Flame (3)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Clairvoyance (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Ineffable Truth (3)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Arcane Studies (4)": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Azure Flame (5)": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Clairvoyance (5)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Ineffable Truth (5)": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".18 Derringer": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Grimm's Fairy Tales": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Old Keyring": { - "tokenType": "resource", - "tokenCount": 2 - }, - ".18 Derringer (2)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Chainsaw (4)": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Becky": { - "tokenType": "resource", - "tokenCount": 2 - }, - "Book of Psalms": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Cryptographic Cipher": { - "tokenType": "resource", - "tokenCount": 3 - }, - ".25 Automatic": { - "tokenType": "resource", - "tokenCount": 4 - }, - "Obfuscation": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Eldritch Sophist": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Armageddon": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Eye of Chaos": { - "tokenType": "resource", - "tokenCount": 3 - }, - "Shroud of Shadows": { - "tokenType": "resource", - "tokenCount": 3 - }, - "xxx": { - "tokenType": "resource", - "tokenCount": 3 - } - } - ]] - LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) - PLAYER_CARD_DATA = JSON.decode(PLAYER_CARD_DATA_JSON) - - PLAYER_CARD_TOKEN_OFFSETS = { - [1] = { - { 0, 3, -0.2 }, - }, - [2] = { - { 0.4, 3, -0.2 }, - { -0.4, 3, -0.2 }, - }, - [3] = { - { 0, 3, -0.9 }, - { 0.4, 3, -0.2 }, - { -0.4, 3, -0.2 }, - }, - [4] = { - { 0.4, 3, -0.9 }, - { -0.4, 3, -0.9 }, - { 0.4, 3, -0.2 }, - { -0.4, 3, -0.2 } - }, - [5] = { - { 0.7, 3, -0.9 }, - { 0, 3, -0.9 }, - { -0.7, 3, -0.9 }, - { 0.4, 3, -0.2 }, - { -0.4, 3, -0.2 } - }, - [6] = { - { 0.7, 3, -0.9 }, - { 0, 3, -0.9 }, - { -0.7, 3, -0.9 }, - { 0.7, 3, -0.2 }, - { 0, 3, -0.2 }, - { -0.7, 3, -0.2 }, - }, - [7] = { - { 0.7, 3, -0.9 }, - { 0, 3, -0.9 }, - { -0.7, 3, -0.9 }, - { 0.7, 3, -0.2 }, - { 0, 3, -0.2 }, - { -0.7, 3, -0.2 }, - { 0, 3, 0.5 }, - }, - [8] = { - { 0.7, 3, -0.9 }, - { 0, 3, -0.9 }, - { -0.7, 3, -0.9 }, - { 0.7, 3, -0.2 }, - { 0, 3, -0.2 }, - { -0.7, 3, -0.2 }, - { -0.35, 3, 0.5 }, - { 0.35, 3, 0.5 }, - }, - [9] = { - { 0.7, 3, -0.9 }, - { 0, 3, -0.9 }, - { -0.7, 3, -0.9 }, - { 0.7, 3, -0.2 }, - { 0, 3, -0.2 }, - { -0.7, 3, -0.2 }, - { 0.7, 3, 0.5 }, - { 0, 3, 0.5 }, - { -0.7, 3, 0.5 }, - }, - [12] = { - { 0.7, 3, -0.9 }, - { 0, 3, -0.9 }, - { -0.7, 3, -0.9 }, - { 0.7, 3, -0.2 }, - { 0, 3, -0.2 }, - { -0.7, 3, -0.2 }, - { 0.7, 3, 0.5 }, - { 0, 3, 0.5 }, - { -0.7, 3, 0.5 }, - { 0.7, 3, 1.2 }, - { 0, 3, 1.2 }, - { -0.7, 3, 1.2 }, - } - - } - - modeData = { - ['Core Set'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['The Devourer Below'] = { - easy = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' }, - normal = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' }, - hard = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' }, - expert = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' } - }, - -----------------The Dunwich Legacy - - ['The Dunwich Legacy'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'red', 'blue' } } - }, - ['The Miskatonic Museum'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Essex County Express'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Blood on the Altar'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Undimensioned and Unseen'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Where Doom Awaits'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Lost in Time and Space'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - -----------------The Path to Carcosa - - ['The Path to Carcosa'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'skull', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'red', 'blue' } } - }, - ['The Last King'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } - }, - ['Echoes of the Past'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } - }, - ['The Unspeakable Oath'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } - }, - ['A Phantom of Truth'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } - }, - ['The Pallid Mask'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } - }, - ['Black Stars Rise'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } - }, - ['Dim Carcosa'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'red', 'blue' } } - }, - -----------------The Forgotten Age - - ['The Forgotten Age'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } - }, - ['The Doom of Eztli'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Threads of Fate'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Boundary Beyond'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The City of Archives'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Depths of Yoth'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Heart of the Elders'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Shattered Aeons'] = { - standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'elder', 'red', 'blue' } } - }, - - -----------------The Circle Undone - - ['The Circle Undone'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm6', 'm8', 'skull', 'skull', 'red', 'blue' } } - }, - ["At Death's Doorstep"] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Secret Name'] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Wages of Sin'] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['For the Greater Good'] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Union and Disillusion'] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['In the Clutches of Chaos'] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Before the Black Throne'] = { - standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - - - -----------------The Dream-Eaters - - ['TDE_A'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } - }, - ['TDE_B'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } - }, - ['The Search For Kadath'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } - }, - ['A Thousand Shapes of Horror'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } - }, - ['Dark Side of the Moon'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } - }, - ['Point of No Return'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } - }, - ['Where the Gods Dwell'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } - }, - ['Weaver of the Cosmos'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } - }, - - - -----------------The Innsmouth Conspiracy - ['The Innsmouth Conspiracy'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } , - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } - }, - ['In Too Deep'] = { - standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } - }, - - -----------------The Side Missions - --official - ['Curse of the Rougarou'] = { - normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Carnevale of Horrors'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Labyrinths of Lunacy'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'red', 'blue' } }, - hard = { token = { 'p1', '0','m1', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'red', 'blue' } } - }, - ['Guardians of the Abyss'] = { - normal = { token = { 'p1', 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['Excelsior'] = { - normal = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['Read or Die'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['All or Nothing'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - - ['Meowlathotep'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - - --fan-made - ['Carnevale of Spiders'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - - ['The Nephew Calls'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Outsider'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Stranger Things'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Winter Winds'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'skull', 'cultist', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'cultist', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'cultist', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'cultist', 'red', 'blue' } } - }, - ['The Festival'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Forbidding Desert'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } - }, - ['Happys Funhouse'] = { - normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm5', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Knightfall'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'm8', 'cultist', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Last Call at Roxies'] = { - easy = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } - }, - ['The Limens of Belief'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } - }, - ['Blood Spilled in Salem'] = { - normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Bread and Circuses'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['Bridge of Sighs'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['The Collector'] = { - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['The Colour out of Space'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Curse of Amultep'] = { - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['The Dying Star'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'blue', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'blue', 'red', 'blue' } } - }, - ['Against the Wendigo'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Pensher Wyrm'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'elder', 'red', 'blue' } } - }, - ['Approaching Storm'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Into the Shadowlands'] = { - easy = { token = { 'p1', 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['London Set 1'] = { - easy = { token = { 'p2', 'p1', '0', '0', '0', 'm1', 'm2', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm2', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm2', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - }, - ['London Set 2'] = { - normal = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'elder', 'tablet', 'red', 'blue' } }, - }, - ['London Set 3'] = { - normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - }, - ['Delta Green'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['Jennys Choice'] = { - easy = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4','skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm5', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'elder', 'red', 'blue' } } - }, - ['The Blob'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['The Initiation'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } - }, - ['Consternation'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'red', 'blue' } }, - }, - ['Of Sphinx'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'elder', 'cultist', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'elder', 'cultist', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'elder', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['Ordis'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['Darkness Falls'] = { - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - ['War of the Worlds'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } - }, - ['Alice in Wonderland'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } - }, - ['Pokemon'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'm8', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Safari'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['Cerulean'] = { - normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['Erich Zann'] = { - easy = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - normal = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } - }, - ['Kaimonogatari'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'skull', 'skull', 'cultist', 'red', 'blue' } }, - expert = { token = { '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm6', 'm8', 'skull', 'skull', 'cultist', 'red', 'blue' } } - }, - ['Sleepy Hollow'] = { - normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, - }, - ['Flesh'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, - }, - ['Dark Matter'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } } - }, - ['XXXX'] = { - easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, - expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } - }, - - } - - function onSave() - local globalState = JSON.encode(SPAWNED_PLAYER_CARD_GUIDS) - log('saving global state: ' .. globalState) - self.script_state = globalState - end - - function onload(save_state) - if save_state ~= '' then - log('loading global state: ' .. save_state) - SPAWNED_PLAYER_CARD_GUIDS = JSON.decode(save_state) - else - SPAWNED_PLAYER_CARD_GUIDS = {} - end - end - - function getSpawnedPlayerCardGuid(params) - local guid = params[1] - if SPAWNED_PLAYER_CARD_GUIDS == nil then - return nil - end - return SPAWNED_PLAYER_CARD_GUIDS[guid] - end - - function setSpawnedPlayerCardGuid(params) - local guid = params[1] - local value = params[2] - if SPAWNED_PLAYER_CARD_GUIDS ~= nil then - SPAWNED_PLAYER_CARD_GUIDS[guid] = value - return true - end - return false + -- set true to enable debug logging + DEBUG = false + + function log(message) + if DEBUG then + print(message) + end + end + + --[[ + Known locations and clues. We check this to determine if we should + atttempt to spawn clues, first we look for _ and if + we find nothing we look for + format is [location_guid -> clueCount] + ]] + LOCATIONS_DATA_JSON = [[ + { + "Study": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Study_670914": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Attic_377b20": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Attic": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Cellar_5d3bcc": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Cellar": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Bathroom": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Bedroom": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Far Above Your House": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Deep Below Your House": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Northside_86faac": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Northside": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Graveyard": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Miskatonic University_cedb0a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Miskatonic University": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Downtown_1aa7cb": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Downtown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "St. Mary's Hospital": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Easttown_88245c": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Easttown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Southside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Rivertown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Your House_377b20": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Your House_b28633": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Ritual Site": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Arkham Woods_e8e04b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Arkham Woods": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "New Orleans_5ab18a": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "New Orleans": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Riverside_ab9d69": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Riverside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Wilderness_3c5ea8": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Wilderness": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Unhallowed Land_552a1d": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Unhallowed Land": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Flooded Square": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Streets of Venice": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Rialto Bridge": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Venetian Garden": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Guardian": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Canal-side": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Accademia Bridge": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Bridge of Sighs": {"type": "fixed", "value": 2, "clueSide": "back"}, + + "Warren Observatory": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Science Building": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Orne Library": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Administration Building": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Student Union": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Humanities Building": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Dormitories": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + "Faculty Offices": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Faculty Offices_1c567d": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + + "La Bella Luna": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Back Hall Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Museum Entrance": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Security Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Security Office_fcb3e4": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Administration Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Administration Office_d2eb25": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Exhibit Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Exhibit Hall_563240": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Exhibit Hall_f3ffb6": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Exhibit Hall_0b0c58": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Exhibit Hall_2d87e6": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Exhibit Hall_da02ea": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + + "Train Car": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Train Car_f3f902": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Train Car_905f69": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Train Car_a3a321": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Train Car_464528": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Train Car_3cfca4": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Train Car_64ffb0": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Train Car_0fb5f0": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + "Engine Car": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "House in the Reeds": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Osborn's General Store": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Congregational Church": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Bishop's Brook": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Burned Ruins": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Schoolhouse": {"type": "fixed", "value": 1, "clueSide": "back"}, + + "Dunwich Village": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Dunwich Village_ac4427": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Cold Spring Glen": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Cold Spring Glen_e58475": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Ten-Acre Meadow": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Ten-Acre Meadow_05b0dd": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Blasted Heath": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Blasted Heath_995fe7": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Whateley Ruins": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Devil's Hop Yard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Devil's Hop Yard_f7dd31": {"type": "fixed", "value": 2, "clueSide": "back"}, + + "Base of the Hill": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Base of the Hill_80236e": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Ascending Path": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Ascending Path_d3ae26": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Sentinel Peak": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Diverging Path": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Diverging Path_7239aa": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Altered Path": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "The Edge of the Universe": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Tear Through Time": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Prismatic Cascade": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Towering Luminosity": {"type": "fixed", "value": 4, "clueSide": "front"}, + "Tear Through Space": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Endless Bridge": {"type": "fixed", "value": 2, "clueSide": "front"}, + "Dimensional Doorway": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Steps of Y'hagharl": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Unstable Vortex": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Indecipherable Stairs": {"type": "fixed", "value": 1, "clueSide": "front"}, + + "Backstage Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Backstage Doorway_0797a9": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Lobby Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Lobby Doorway_7605cf": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Lobby": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Backstage": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Balcony": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Foyer": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Historical Society": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Historical Society_40f79d": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Historical Society_b352f8": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Historical Society_0cf5d5": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Historical Society_abc0cb": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Historical Society_ab6a72": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Hidden Library": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + + "Patient Confinement": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Asylum Halls": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Asylum Halls_f99530": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Asylum Halls_576595": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Infirmary": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Basement Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Yard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Garden": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Kitchen": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Mess Hall": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Grand Guignol": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Montmartre": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Montmartre_cbaacc": {"type": "perPlayer", "value": 0, "clueSide": "front"}, + "Montparnasse": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Notre-Dame": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Gare d'Orsay": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Opéra Garnier": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Canal Saint-Martin": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Le Marais": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Gardens of Luxembourg": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Père Lachaise Cemetery": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Catacombs": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Catacombs_29170f": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Catacombs_f1237c": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Catacombs_c3151e": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Catacombs_14b1cb": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Catacombs_81920c": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Catacombs_c14c8b": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Catacombs_ea2a55": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Catacombs_8bcab3": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Catacombs_7c7f4a": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Catacombs_80cf41": {"type": "fixed", "value": 0, "clueSide": "back"}, + + "Abbey Church": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Porte de l'Avancée": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Grand Rue": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Cloister": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Knight's Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Chœur Gothique": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Outer Wall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Outer Wall_014bd6": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "North Tower": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "North Tower_69eae5": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Chapel of St. Aubert": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + "Chapel of St. Aubert_e75ba8": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Abbey Tower": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + "Abbey Tower_2f3d21": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Shores of Hali": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Dark Spires": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Palace of the King": {"type": "perPlayer", "value": 3, "clueSide": "front"}, + "Palace of the King_60d758": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Ruins of Carcosa": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Dim Streets": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Depths of Demhe": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Bleak Plains": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Recesses of Your Own Mind": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "The Throne Room": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Stage of the Ward Theatre": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "Serpent’s Haven": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Ruins of Eztli": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Rope Bridge": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Overgrown Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "River Canyon": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Path of Thorns": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Temple of the Fang": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Circuitous Trail": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Riverside Temple": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Waterfall": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Trail of the Dead": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Cloud Forest": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "Chamber of Time": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Ancient Hall": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Ancient Hall_b9acb8": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Grand Chamber": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Entryway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Underground Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Burial Pit": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Secret Passage": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Snake Pit": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Throne Room": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Mosaic Chamber": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Tomb of the Ancients": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Town Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Curiositie Shoppe": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "At the Station": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "At the Station_e0833c": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Missing Persons": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "The Relic is Missing!": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Trial of the Huntress": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Search for the Meaning": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Seeking Trouble": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Seeking Trouble_42f93b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + + "Sacred Woods": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Chapultepec Hill": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Chapultepec Hill_baec21": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Canals of Tenochtitlán": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Lake Xochimilco": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Lake Xochimilco_59bf7d": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Templo Mayor": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Templo Mayor_fb0083": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Temples of Tenochtitlán": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Temples of Tenochtitlán_80cef8": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Mouth of K'n-yan_38a3e5": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Stone Altar": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Time-Wracked Woods": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Vast Passages": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Perilous Gulch": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Dark Hollow": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Hall of Idolatry": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Crystal Pillars": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Ruins of K’n-yan": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Chthonian Depths": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Subterranean Swamp": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Treacherous Descent": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Interview Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Interview Room_b1861c": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Halls of Pnakotus": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Deconstruction Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Towers of Pnakotus": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Laboratory of the Great Race": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Yithian Orrery": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Great Library": {"type": "fixed", "value": 4, "clueSide": "back"}, + "Cyclopean Vaults": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Alien Conservatory": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "City of the Serpents": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Bridge over N'kai": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Abandoned Site": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Caverns of Yoth": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Hall of Heresy": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Bright Canyon": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Forked Path": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + + "Nexus of N'kai": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "A Pocket in Time": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "City of the Unseen": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Valusia": {"type": "fixed", "value": 2, "clueSide": "front"}, + "Great Hall of Celeano": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Buenos Aires": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Ultima Thule": {"type": "fixed", "value": 2, "clueSide": "front"}, + + "Shores of R’lyeh": {"type": "fixed", "value": 2, "clueSide": "front"}, + "Atlantis": {"type": "fixed", "value": 2, "clueSide": "front"}, + "Pnakotus": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Ruins of New York": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Yuggoth": {"type": "fixed", "value": 3, "clueSide": "front"}, + "Mu": {"type": "fixed", "value": 4, "clueSide": "front"}, + "Plateau of Leng_0ab6ff": {"type": "fixed", "value": 1, "clueSide": "front"}, + + "Billiards Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Billiards Room_33990b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Trophy Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Trophy Room_e9160a": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Master Bedroom": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Balcony_1b5483": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Office_a1bd9a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Witch-Haunted Woods_1539ea": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Witch-Haunted Woods": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Witch-Haunted Woods_d3f8c3": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Witch-Haunted Woods_eca18e": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Paths into Twilight": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + + "The Imperial Entrance": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Dark Stairwell": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Stairway": {"type": "fixed", "value": 1, "clueSide": "back"}, + "The Balcony": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Back Booths": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Lobby": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Backroom Door": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Backroom Door_ed439d": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Dining Area": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "The Dance Floor": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Gateway to the East": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Back Alley": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Mingzhu Laundry": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Dragon's Den": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "The Phoenix's Nest": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Golden Temple of the Heavens": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Flea Market": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Zihao's House of Fighting Arts": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Daiyu's Tea Garden": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Moldy Halls": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Decrepit Door": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Walter Gilman's Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Unknown Places_b538f8": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Unknown Places_7bea34": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Unknown Places": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Unknown Places_9a471d": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Unknown Places_0ac3ea": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Strange Geometry": {"type": "fixed", "value": 1, "clueSide": "front"}, + "Site of the Sacrifice": {"type": "perPlayer", "value": 3, "clueSide": "back"}, + + "Hangman's Brook": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Abandoned Chapel": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Haunted Fields": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Lobby_1c2dfe": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Lobby_bcd556": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Lodge Gates_fa6a29": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Lodge Gates": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Lodge Cellar": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Lodge Cellar_8ea4fd": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Lounge": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Vault": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Inner Sanctum": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Library": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Library_47ccbc": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Sanctum Doorway": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Sanctum Doorway_4da6c3": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "The Geist-Trap": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Forbidding Shore": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Unvisited Isle": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Rivertown_92ee68": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Rivertown_db4b20": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Southside_c898a0": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Southside_e7f5fa": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Silver Twilight Lodge": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Silver Twilight Lodge_17e686": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Hangman's Hill": {"type": "fixed", "value": 0, "clueSide": "back"}, + "Hangman's Hill_5f4d8a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Cosmic Ingress": {"type": "fixed", "value": 3, "clueSide": "back"}, + "Cosmos": {"type": "fixed", "value": 1, "clueSide": "back"}, + "Cosmos_a89dbf": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Cosmos_1a0ad2": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Cosmos_30fc53": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Cosmos_8f3e16": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Cosmos_4e8ae3": {"type": "fixed", "value": 2, "clueSide": "back"}, + "Cosmos_a8d84d": {"type": "fixed", "value": 4, "clueSide": "back"}, + "Cosmos_7a3ece": {"type": "fixed", "value": 6, "clueSide": "back"}, + "Cosmos_311eb1": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Seventy Steps": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Seven Hundred Steps": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Base of the Steps": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Enchanted Woods": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Stairwell": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Basement Door_42fa87": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Basement Door": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Waiting Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Emergency Room": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Experimental Therapies Ward": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Records Office": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Foyer_9a9f9a": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Room 245": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Hotel Roof": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Office_b3ed47": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Room 212": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Basement": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Second Floor Hall": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Room 225": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Restaurant": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Suite Balcony": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Ulthar": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Dylath-Leen": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Mt. Ngranek": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Baharna": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Zulan-Thek": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Sarnath": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "City-Which-Appears-On-No-Map": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Celephaïs": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Nameless Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Kadatheron": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Ilek-Vad": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Ruins of Ib": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Temple of Unattainable Desires": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Hazuth-Kleg": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Serannian": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Mysterious Stairs": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Mysterious Stairs_df1a40": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Attic_10faf9": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Unmarked Tomb": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Upstairs Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Front Porch": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Downstairs Doorway": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Downstairs Doorway_c93906": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Burial Ground": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Temple of the Moon Lizard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "City of the Moon-Beasts": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Moon-Forest": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Dark Crater": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Caverns Beneath the Moon": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Black Core": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Light Side of the Moon": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "City of Gugs": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Vaults of Zin": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Plain of the Ghouls": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Sea of Bones": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Vale of Pnath": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Crag of the Ghouls": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Sea of Pitch": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Plateau of Leng": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Cold Wastes": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Monastery of Leng": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Onyx Gates": {"type": "fixed", "value": 12, "clueSide": "back"}, + "Forsaken Tower": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "The Crater": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Quarantine Zone": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Quarantine Zone_5f2a9b": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Quarantine Zone_4a8e9c": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Quarantine Zone_5193e9": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Quarantine Zone_b3a920": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "The Great Web": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Great Web_39ace3": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "The Great Web_727790": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "The Great Web_5c5ec4": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "The Great Web_361fd7": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "The Great Web_dfdc8c": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Expedition Camp": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Desert Oasis": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Untouched Vault": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Sands of Dashur": {"type": "perPlayer", "value": 0, "clueSide": "front"}, + "Sandswept Ruins": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Nile River": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Faceless Sphinx": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Dunes of the Sahara": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Streets of Cairo": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Cairo Bazaar": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Temple Courtyard": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Museum of Egyptian Antiquities": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Outskirts of Cairo": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + + "Eldritch Gate": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Mist-Filled Caverns": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Stairway to Sarkomand": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Tunnels under Ngranek": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "The Great Abyss": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "A Dream Betwixt": {"type": "perPlayer", "value": 0, "clueSide": "front"}, + + "Velma's Doghouse": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Barkham City Pound": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Barkham Asylum": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Beasttown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Tailside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Slobbertown": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Snoutside": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Muttskatonic University": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Boneyard": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "St. Mary's Animal Hospital": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Unfamiliar Chamber": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Tidal Tunnel": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Tidal Tunnel_0f20fc": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Tidal Tunnel_d5566b": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Tidal Tunnel_dc9eb7": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + "Tidal Tunnel_513d82": {"type": "perPlayer", "value": 0, "clueSide": "back"}, + + "First National Grocery": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Marsh Refinery": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Innsmouth Square": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Innsmouth Harbour": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Fish Street Bridge_b6b9b7": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Gilman House": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Little Bookshop": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + + "Innsmouth Jail_f63738": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "New Church Green_d1ef9c": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Sawbone Alley_899c2c": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "The House on Water Street_e4f53a": {"type": "perPlayer", "value": 2, "clueSide": "front"}, + "Shoreward Slums_24e42d": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + "Esoteric Order of Dagon_28c301": {"type": "perPlayer", "value": 1, "clueSide": "front"}, + + "Esoteric Order of Dagon_ef8cef": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "New Church Green_921a9b": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Marsh Refinery_44c342": {"type": "fixed", "value": 1, "clueSide": "back"}, + "The House on Water Street_104e07": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "The Little Bookshop_a17a82": {"type": "fixed", "value": 1, "clueSide": "back"}, + "First National Grocery_9ae75c": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Fish Street Bridge_a358fc": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Innsmouth Harbour_30b2c0": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Sawbone Alley_e58cff": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Gilman House_e589b8": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "Innsmouth Jail_755fc0": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Shoreward Slums_c0d0df": {"type": "perPlayer", "value": 1, "clueSide": "back"}, + "Desolate Coastline": {"type": "fixed", "value": 1, "clueSide": "back"}, + + "XXXX": {"type": "perPlayer", "value": 2, "clueSide": "back"}, + "xxx": {"type": "perPlayer", "value": 2, "clueSide": "back"} + } + ]] + --[[ + Player cards with token counts and types + ]] + PLAYER_CARD_DATA_JSON = [[ + { + "Flashlight": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Shrivelling": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Shrivelling (3)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Grotesque Statue (4)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Forbidden Knowledge": { + "tokenType": "resource", + "tokenCount": 4 + }, + ".45 Automatic": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Shotgun (4)": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Liquid Courage": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Song of the Dead (2)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Cover Up": { + "tokenType": "clue", + "tokenCount": 3 + }, + "Roland's .38 Special": { + "tokenType": "resource", + "tokenCount": 4 + }, + "First Aid": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Scrying": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".41 Derringer": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Painkillers": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Smoking Pipe": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Clarity of Mind": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Rite of Seeking": { + "tokenType": "resource", + "tokenCount": 3 + }, + "M1918 BAR (4)": { + "tokenType": "resource", + "tokenCount": 8 + }, + "Ornate Bow (3)": { + "tokenType": "resource", + "tokenCount": 1 + }, + ".41 Derringer (2)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Suggestion (4)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Chicago Typewriter (4)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Lupara (3)": { + "tokenType": "resource", + "tokenCount": 2 + }, + "First Aid (3)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Springfield M1903 (4)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Springfield M1903 (4) (Taboo)": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".32 Colt": { + "tokenType": "resource", + "tokenCount": 6 + }, + "Venturer": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Lockpicks (1)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Finn's Trusty .38": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".45 Automatic (2)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Lightning Gun (5)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Strange Solution (4)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Strange Solution (4):Acidic Ichor": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Strange Solution (4):Empowering Elixir": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Arcane Insight (4)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Archaic Glyphs (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "In the Know (1)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Rite of Seeking (4)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Alchemical Transmutation": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Scrying (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Shrivelling (5)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Mists of R'lyeh": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Mists of R'lyeh (4)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Colt Vest Pocket": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Old Hunting Rifle (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Thermos": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Feed the Mind (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Seal of the Seventh Sign (5)": { + "tokenType": "resource", + "tokenCount": 7 + }, + "Flamethrower (5)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Flamethrower (5) (Taboo)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Pnakotic Manuscripts (5)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Kerosene (1)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Shards of the Void (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Try and Try Again (1)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Arcane Initiate": { + "tokenType": "doom", + "tokenCount": 1 + }, + "Detective's Colt 1911s": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Extra Ammunition (1)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Rite of Seeking (2)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Arcane Initiate (3)": { + "tokenType": "doom", + "tokenCount": 1 + }, + "Clarity of Mind (3)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Fingerprint Kit": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Truth from Fiction": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Enchanted Blade": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Tennessee Sour Mash": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Scroll of Secrets": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Scroll of Secrets (Taboo)": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".45 Thompson": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Mr. \"Rook\"": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Mr. \"Rook\" (Taboo)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Scroll of Secrets (3):Seeker": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Scroll of Secrets (3) (Taboo):Seeker": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Scroll of Secrets (3):Mystic": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Scroll of Secrets (3) (Taboo):Mystic": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Enchanted Blade (3):Guardian": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Enchanted Blade (3):Mystic": { + "tokenType": "resource", + "tokenCount": 4 + }, + ".45 Thompson (3)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Esoteric Atlas (1)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Tennessee Sour Mash (3):Rogue": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Tennessee Sour Mash (3):Survivor": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Mk 1 Grenades (4)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Dayana Esperence (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Pendant of the Queen": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".32 Colt (2)": { + "tokenType": "resource", + "tokenCount": 6 + }, + "Alchemical Transmutation (2)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Suggestion (1)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Gate Box": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Tony's .38 Long Colt": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Gregory Gry": { + "tokenType": "resource", + "tokenCount": 9 + }, + "Scroll of Prophecies": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Healing Words": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Otherworld Codex (2)": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".35 Winchester": { + "tokenType": "resource", + "tokenCount": 5 + }, + ".35 Winchester (Taboo)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Old Book of Lore (3)": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Sawed-Off Shotgun (5)": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Mind's Eye (2)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Colt Vest Pocket (2)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Mists of R'lyeh (2)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "The Chthonian Stone (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Flesh Ward": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Physical Training (4)": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Encyclopedia": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Feed the Mind": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Forbidden Tome": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Esoteric Atlas (2)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "The Necronomicon (5)": { + "tokenType": "resource", + "tokenCount": 6 + }, + "The Necronomicon (5) (Taboo)": { + "tokenType": "resource", + "tokenCount": 6 + }, + "Mauser C96": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Liquid Courage (1)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Mauser C96 (2)": { + "tokenType": "resource", + "tokenCount": 5 + }, + "Beretta M1918 (4)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Scrying Mirror": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Azure Flame": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Clairvoyance": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Ineffable Truth": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Grotesque Statue (2)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Azure Flame (3)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Clairvoyance (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Ineffable Truth (3)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Arcane Studies (4)": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Azure Flame (5)": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Clairvoyance (5)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Ineffable Truth (5)": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".18 Derringer": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Grimm's Fairy Tales": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Old Keyring": { + "tokenType": "resource", + "tokenCount": 2 + }, + ".18 Derringer (2)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Chainsaw (4)": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Becky": { + "tokenType": "resource", + "tokenCount": 2 + }, + "Book of Psalms": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Cryptographic Cipher": { + "tokenType": "resource", + "tokenCount": 3 + }, + ".25 Automatic": { + "tokenType": "resource", + "tokenCount": 4 + }, + "Obfuscation": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Eldritch Sophist": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Armageddon": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Eye of Chaos": { + "tokenType": "resource", + "tokenCount": 3 + }, + "Shroud of Shadows": { + "tokenType": "resource", + "tokenCount": 3 + }, + "xxx": { + "tokenType": "resource", + "tokenCount": 3 + } + } + ]] + LOCATIONS_DATA = JSON.decode(LOCATIONS_DATA_JSON) + PLAYER_CARD_DATA = JSON.decode(PLAYER_CARD_DATA_JSON) + + PLAYER_CARD_TOKEN_OFFSETS = { + [1] = { + { 0, 3, -0.2 }, + }, + [2] = { + { 0.4, 3, -0.2 }, + { -0.4, 3, -0.2 }, + }, + [3] = { + { 0, 3, -0.9 }, + { 0.4, 3, -0.2 }, + { -0.4, 3, -0.2 }, + }, + [4] = { + { 0.4, 3, -0.9 }, + { -0.4, 3, -0.9 }, + { 0.4, 3, -0.2 }, + { -0.4, 3, -0.2 } + }, + [5] = { + { 0.7, 3, -0.9 }, + { 0, 3, -0.9 }, + { -0.7, 3, -0.9 }, + { 0.4, 3, -0.2 }, + { -0.4, 3, -0.2 } + }, + [6] = { + { 0.7, 3, -0.9 }, + { 0, 3, -0.9 }, + { -0.7, 3, -0.9 }, + { 0.7, 3, -0.2 }, + { 0, 3, -0.2 }, + { -0.7, 3, -0.2 }, + }, + [7] = { + { 0.7, 3, -0.9 }, + { 0, 3, -0.9 }, + { -0.7, 3, -0.9 }, + { 0.7, 3, -0.2 }, + { 0, 3, -0.2 }, + { -0.7, 3, -0.2 }, + { 0, 3, 0.5 }, + }, + [8] = { + { 0.7, 3, -0.9 }, + { 0, 3, -0.9 }, + { -0.7, 3, -0.9 }, + { 0.7, 3, -0.2 }, + { 0, 3, -0.2 }, + { -0.7, 3, -0.2 }, + { -0.35, 3, 0.5 }, + { 0.35, 3, 0.5 }, + }, + [9] = { + { 0.7, 3, -0.9 }, + { 0, 3, -0.9 }, + { -0.7, 3, -0.9 }, + { 0.7, 3, -0.2 }, + { 0, 3, -0.2 }, + { -0.7, 3, -0.2 }, + { 0.7, 3, 0.5 }, + { 0, 3, 0.5 }, + { -0.7, 3, 0.5 }, + }, + [12] = { + { 0.7, 3, -0.9 }, + { 0, 3, -0.9 }, + { -0.7, 3, -0.9 }, + { 0.7, 3, -0.2 }, + { 0, 3, -0.2 }, + { -0.7, 3, -0.2 }, + { 0.7, 3, 0.5 }, + { 0, 3, 0.5 }, + { -0.7, 3, 0.5 }, + { 0.7, 3, 1.2 }, + { 0, 3, 1.2 }, + { -0.7, 3, 1.2 }, + } + + } + + modeData = { + ['Core Set'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['The Devourer Below'] = { + easy = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' }, + normal = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' }, + hard = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' }, + expert = { parent = 'Core Set', append = { 'elder' }, message = 'An additional token for the preparation of this scenario has been added to the bag.' } + }, + -----------------The Dunwich Legacy + + ['The Dunwich Legacy'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'red', 'blue' } } + }, + ['The Miskatonic Museum'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Essex County Express'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Blood on the Altar'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Undimensioned and Unseen'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Where Doom Awaits'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Lost in Time and Space'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + -----------------The Path to Carcosa + + ['The Path to Carcosa'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'skull', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'red', 'blue' } } + }, + ['The Last King'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } + }, + ['Echoes of the Past'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } + }, + ['The Unspeakable Oath'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } + }, + ['A Phantom of Truth'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } + }, + ['The Pallid Mask'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } + }, + ['Black Stars Rise'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'red', 'blue' }, random = { {'cultist', 'cultist'}, {'tablet', 'tablet'}, {'elder', 'elder'} } } + }, + ['Dim Carcosa'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'red', 'blue' } } + }, + -----------------The Forgotten Age + + ['The Forgotten Age'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } + }, + ['The Doom of Eztli'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Threads of Fate'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Boundary Beyond'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The City of Archives'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Depths of Yoth'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Heart of the Elders'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Shattered Aeons'] = { + standalone = { token = { 'p1', '0', '0', '0','m1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'elder', 'red', 'blue' } } + }, + + -----------------The Circle Undone + + ['The Circle Undone'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm6', 'm8', 'skull', 'skull', 'red', 'blue' } } + }, + ["At Death's Doorstep"] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Secret Name'] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Wages of Sin'] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['For the Greater Good'] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Union and Disillusion'] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['In the Clutches of Chaos'] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Before the Black Throne'] = { + standalone = { token = { 'p1', '0', '0', 'm1','m1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + + + -----------------The Dream-Eaters + + ['TDE_A'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } + }, + ['TDE_B'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } + }, + ['The Search For Kadath'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } + }, + ['A Thousand Shapes of Horror'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } + }, + ['Dark Side of the Moon'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } + }, + ['Point of No Return'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } + }, + ['Where the Gods Dwell'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } + }, + ['Weaver of the Cosmos'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'skull', 'cultist', 'elder', 'elder', 'red', 'blue' } } + }, + + + -----------------The Innsmouth Conspiracy + ['The Innsmouth Conspiracy'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } , + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } + }, + ['In Too Deep'] = { + standalone = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } + }, + + -----------------The Side Missions + --official + ['Curse of the Rougarou'] = { + normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Carnevale of Horrors'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Labyrinths of Lunacy'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'red', 'blue' } }, + hard = { token = { 'p1', '0','m1', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'red', 'blue' } } + }, + ['Guardians of the Abyss'] = { + normal = { token = { 'p1', 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['Excelsior'] = { + normal = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['Read or Die'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['All or Nothing'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + + ['Meowlathotep'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + + --fan-made + ['Carnevale of Spiders'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + + ['The Nephew Calls'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Outsider'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Stranger Things'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Winter Winds'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'skull', 'cultist', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'cultist', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'cultist', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'cultist', 'red', 'blue' } } + }, + ['The Festival'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Forbidding Desert'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } + }, + ['Happys Funhouse'] = { + normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm5', 'm7', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Knightfall'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'm8', 'cultist', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Last Call at Roxies'] = { + easy = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'elder', 'elder', 'red', 'blue' } } + }, + ['The Limens of Belief'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } } + }, + ['Blood Spilled in Salem'] = { + normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Bread and Circuses'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['Bridge of Sighs'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['The Collector'] = { + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['The Colour out of Space'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Curse of Amultep'] = { + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['The Dying Star'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'blue', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'blue', 'red', 'blue' } } + }, + ['Against the Wendigo'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Pensher Wyrm'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'elder', 'red', 'blue' } } + }, + ['Approaching Storm'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Into the Shadowlands'] = { + easy = { token = { 'p1', 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['London Set 1'] = { + easy = { token = { 'p2', 'p1', '0', '0', '0', 'm1', 'm2', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm2', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm2', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + }, + ['London Set 2'] = { + normal = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'elder', 'tablet', 'red', 'blue' } }, + }, + ['London Set 3'] = { + normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + }, + ['Delta Green'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['Jennys Choice'] = { + easy = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4','skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm5', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'elder', 'red', 'blue' } } + }, + ['The Blob'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['The Initiation'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } + }, + ['Consternation'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'm7', 'skull', 'skull', 'skull', 'red', 'blue' } }, + }, + ['Of Sphinx'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'elder', 'cultist', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'skull', 'elder', 'cultist', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'elder', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['Ordis'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'elder', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['Darkness Falls'] = { + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + ['War of the Worlds'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } + }, + ['Alice in Wonderland'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'm5', 'm6', 'skull', 'skull', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'skull', 'skull', 'elder', 'red', 'blue' } } + }, + ['Pokemon'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'm8', 'skull', 'skull', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Safari'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['Cerulean'] = { + normal = { token = { 'p1', '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', 'm1', 'm2', 'm3', 'm3', 'm4', 'm6', 'skull', 'skull', 'cultist', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['Erich Zann'] = { + easy = { token = { 'p1', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + normal = { token = { 'p1', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } } + }, + ['Kaimonogatari'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'skull', 'skull', 'cultist', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm2', 'm2', 'm3', 'm4', 'm4', 'm5', 'skull', 'skull', 'cultist', 'red', 'blue' } }, + expert = { token = { '0', '0', 'm1', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm6', 'm8', 'skull', 'skull', 'cultist', 'red', 'blue' } } + }, + ['Sleepy Hollow'] = { + normal = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + hard = { token = { 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'skull', 'cultist', 'tablet', 'elder', 'red', 'blue' } }, + }, + ['Flesh'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm3', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', 'm1', 'm1', 'm2', 'm3', 'm3', 'm4', 'm4', 'm6', 'skull', 'skull', 'cultist', 'tablet', 'tablet', 'red', 'blue' } }, + }, + ['Dark Matter'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'cultist', 'red', 'blue' } } + }, + ['XXXX'] = { + easy = { token = { 'p1', 'p1', '0', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + normal = { token = { 'p1', '0', '0', 'm1', 'm1', 'm1', 'm2', 'm2', 'm3', 'm4', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + hard = { token = { '0', '0', '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm5', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } }, + expert = { token = { '0', 'm1', 'm1', 'm2', 'm2', 'm3', 'm3', 'm4', 'm4', 'm5', 'm6', 'm8', 'skull', 'skull', 'cultist', 'tablet', 'red', 'blue' } } + }, + + } + + function onSave() + local globalState = JSON.encode(SPAWNED_PLAYER_CARD_GUIDS) + log('saving global state: ' .. globalState) + self.script_state = globalState + end + + function onload(save_state) + if save_state ~= '' then + log('loading global state: ' .. save_state) + SPAWNED_PLAYER_CARD_GUIDS = JSON.decode(save_state) + else + SPAWNED_PLAYER_CARD_GUIDS = {} + end + end + + function getSpawnedPlayerCardGuid(params) + local guid = params[1] + if SPAWNED_PLAYER_CARD_GUIDS == nil then + return nil + end + return SPAWNED_PLAYER_CARD_GUIDS[guid] + end + + function setSpawnedPlayerCardGuid(params) + local guid = params[1] + local value = params[2] + if SPAWNED_PLAYER_CARD_GUIDS ~= nil then + SPAWNED_PLAYER_CARD_GUIDS[guid] = value + return true + end + return false end \ No newline at end of file diff --git a/unpacked/Custom_Tile Deck Importer 928c8e.ttslua b/unpacked/Custom_Tile Deck Importer 928c8e.ttslua index 8f21071aa..9c7c3089f 100644 --- a/unpacked/Custom_Tile Deck Importer 928c8e.ttslua +++ b/unpacked/Custom_Tile Deck Importer 928c8e.ttslua @@ -1,574 +1,574 @@ ---[[ Lua code. See documentation: http://berserk-games.com/knowledgebase/scripting/ --]] - ---[[ The onLoad event is called after the game save finishes loading. --]] -function onLoad() - --[[ print('onLoad!') --]] - init() - -- Setup... - publicDeckURL="https://arkhamdb.com/api/public/decklist/" - privateDeckURL="https://arkhamdb.com/api/public/deck/" - cardURL="https://arkhamdb.com/api/public/card/" - tabooListURL="https://arkhamdb.com/api/public/taboos/" - subnameCards={{name="Randolph Carter",xp=0},{name="Dream Diary",xp=3},{name="Relic of Ages",xp=0},{name="The Necronomicon",xp=0},{name="Archaic Glyphs",xp=3},{name="Strange Solution",xp=4},{name="Forbidden Tome",xp=3},{name="Relic of Ages",xp=0}, {name="Ancient Stone",xp=4}, {"Dream Diary",xp=0},{name="Empower Self",xp=2}} - extraPermanents={["Duke"]=true,["Sophie"]=true,["Gate Box"]=true,["Dark Insight"]=true} - multiClassCards={{name=".45 Thompson",xp=3},{name="Scroll of Secrets",xp=3},{name="Tennessee Sour Mash",xp=3},{name="Enchanted Blade",xp=3},{name="Grisly Totem",xp=3}} - returningCards={{name="On Your Own"}} - advancedSignatures={{name="Daisy's Tote Bag"},{name="The Necronomicon"},{name="On the Lam"},{name="Hospital Debts"}} - bondedCardsOneThree={{name="Hallowed Mirror",bondedName="Soothing Melody",bondedCode=05314},{name="Occult Lexicon",bondedName="Blood-Rite",bondedCode=05317},{name="The Hungering Blade",bondedName="Bloodlust",bondedCode=06019},{name="Nightmare Bauble",bondedName="Dream Parasite",bondedCode=06331},{name="Miss Doyle",bondedName="Hope",bondedCode=06031,bondedNameSecond="Zeal",bondedCodeSecond=06032,bondedNameThird="Augur",bondedCodeThird=06033}} - bondedCardsBoolean = {{name="Gate Box",bondedName="Dream-Gate",bondedCode="06015a",bondCount=1},{name="Crystallizer of Dreams",bondedName="Guardian of the Crystallizer",bondedCode=06025,bondCount=2},{name="Dream Diary",bondedName="Essence of the Dream",bondedCode=06113,bondCount=1},{name="Empty Vessel",bondedName="Wish Eater",bondedCode=06277,bondCount=1},{name="Segment of Onyx",bondedName="Pendant of the Queen",bondedCode=06022,bondCount=1},{name="Stargazing",bondedName="The Stars Are Right",bondedCode=06028,bondCount=2},{name="Summoned Hound",bondedName="Unbound Beast",bondedCode=06283,bondCount=2}} - privateDeck = true - permanents = true - - local tileGUID = '928c8e' - tile = getObjectFromGUID(tileGUID) - makeText() - makeButton() - makeCheckboxPP() - makeCheckboxPerms() - - -- Get current taboolist - tabooList = {} - WebRequest.get(tabooListURL, self, 'tabooListCallback') -end - -function spawnZone() - -- Clean up scripting zone - if pcZone then - pcZone.destruct() - end - if weaknessZone then - weaknessZone.destruct() - end - deckPos = LocalPos(self,{-1.85,1.5,1.8}) - permPos = LocalPos(self,{-4.63,1.5,1.8}) - local pcZonePos = LocalPos(self,{4.75, 2.6 , 1.8}) - zoneSpawn = {position = pcZonePos - , scale = { 10.57, 5.1, 10.47 } - , type = 'ScriptingTrigger' --- , callback = 'zoneCallback' - , callback_owner = self - , rotation = self.getRotation() } - pcZone = spawnObject(zoneSpawn) - - -- get a scripting zone at the weakness deck - --local weaknessZonePosition = self.positionToWorld({-7.5, 2.6 , 1.8}) - local weaknessZonePosition = LocalPos(self, {-7.5, 0 , 1.8}) - weaknessZone = spawnObject({ - position = weaknessZonePosition, - type = 'ScriptingTrigger', - rotation = self.getRotation() - }) - - for i=1,1 do - coroutine.yield(0) - end - - local objectsInZone = pcZone.getObjects() - for i,v in pairs(objectsInZone) do - if v.tag == 'Deck' then - playerCardDeck = v - end - end - - local objectsInZone = weaknessZone.getObjects() - for i,v in pairs(objectsInZone) do - if v.getName() == 'All Weaknesses' then - weaknessDeck = v - end - end - - -- Get deck from ArkhamDB.. - local deckURL - if privateDeck then deckURL = privateDeckURL - else deckURL = publicDeckURL - end - - WebRequest.get(deckURL .. deckID, self, 'deckReadCallback') - - return 1 -end - -function init() - cardList = {} - doneSlots = 0 - playerCardDeck = {} - weaknessDeck = {} - totalCards = 0 - tabooID = 0 -end - -function buttonClicked() - -- Reset - init() - -- Spawn scripting zone - startLuaCoroutine(self, "spawnZone") -end - -function checkboxPPClicked() - buttons = tile.getButtons() - for k,v in pairs(buttons) do - if (v.label == "Private deck") then - local button_parameters = {} - button_parameters.label = "Published deck" - button_parameters.index = v.index - tile.editButton(button_parameters) - privateDeck = false - else - if (v.label == "Published deck") then - local button_parameters = {} - button_parameters.label = "Private deck" - button_parameters.index = v.index - tile.editButton(button_parameters) - privateDeck = true - end - end - end -end - -function checkboxPermsClicked() - buttons = tile.getButtons() - for k,v in pairs(buttons) do - if (v.label == "Permanents") then - local button_parameters = {} - button_parameters.label = "No permanents" - button_parameters.index = v.index - tile.editButton(button_parameters) - permanents = false - else - if (v.label == "No permanents") then - local button_parameters = {} - button_parameters.label = "Permanents" - button_parameters.index = v.index - tile.editButton(button_parameters) - permanents = true - end - end - end -end - -function deckReadCallback(req) - -- Result check.. - if req.is_done and not req.is_error - then - if string.find(req.text, "") - then - broadcastToAll("Private deck "..deckID.." is not shared", {0.5,0.5,0.5}) - return - end - JsonDeckRes = JSON.decode(req.text) - else - print (req.error) - return - end - if (JsonDeckRes == nil) - then - broadcastToAll("Deck not found!", {0.5,0.5,0.5}) - return - else - print("Found decklist: "..JsonDeckRes.name) - end - -- Count number of cards in decklist - numSlots=0 - for cardid,number in - pairs(JsonDeckRes.slots) - do - numSlots = numSlots + 1 - end - - -- Check for taboos - tabooID = JsonDeckRes.taboo_id - if tabooID - then - print("Using List of Taboos from "..tabooList[tabooID].date..".") - end - - -- Save card id, number in table and request card info from ArkhamDB - for cardID,number in pairs(JsonDeckRes.slots) - do - local row = {} - row.cardName = "" - row.cardCount = number - cardList[cardID] = row - WebRequest.get(cardURL .. cardID, self, 'cardReadCallback') - totalCards = totalCards + number - end -end - -function cardReadCallback(req) - -- Result check.. - if req.is_done and not req.is_error - then - -- Find unicode before using JSON.decode since it doesnt handle hex UTF-16 - local tmpText = string.gsub(req.text,"\\u(%w%w%w%w)", convertHexToDec) - JsonCardRes = JSON.decode(tmpText) - else - print(req.error) - return - end - - -- Update card name in table - if(JsonCardRes.xp == nil or JsonCardRes.xp == 0) - then - cardList[JsonCardRes.code].cardName = JsonCardRes.real_name - else - cardList[JsonCardRes.code].cardName = JsonCardRes.real_name .. " (" .. JsonCardRes.xp .. ")" - end - - -- Make Subname blank if it does not exist - if (JsonCardRes.subname == nil and (JsonCardRes.subtype_name ~= "Basic Weakness" and JsonCardRes.subtype_name ~= "Weakness")) - then - cardList[JsonCardRes.code].subName = "" - end - - -- Check for subname - for k,v in pairs(subnameCards) do - if (v.name == JsonCardRes.real_name and (v.xp == JsonCardRes.xp or JsonCardRes.xp == nil)) - then - cardList[JsonCardRes.code].subName = JsonCardRes.subname - end - end - - -- Check for multiclass - for k,v in pairs(multiClassCards) do - if (v.name == JsonCardRes.real_name and (v.xp == JsonCardRes.xp or JsonCardRes.xp == nil)) - then - cardList[JsonCardRes.code].subName = JsonCardRes.faction_name - end - end - - -- Check for returning cards (cards with the same name/level but different and from a new set) - for k,v in pairs(returningCards) do - if (v.name == JsonCardRes.real_name and JsonCardRes.pack_name == "Return to the Forgotten Age") - then - cardList[JsonCardRes.code].subName = "Permanent" - end - end - - -- Check for advanced signature cards (this happens after subname check, so it should be fine) - for k,v in pairs(advancedSignatures) do - if (v.name == JsonCardRes.real_name) - then - if (JsonCardRes.pack_name == "Read or Die" or JsonCardRes.pack_name == "All or Nothing") - then - if (v.name == "The Necronomicon") - then - cardList[JsonCardRes.code].subName = "John Dee Translation (Advanced)" - else - cardList[JsonCardRes.code].subName = "Advanced" - end - end - end - end - - -- Check if card is permanent (if separation is selected) - if permanents then - if (JsonCardRes.permanent == true or extraPermanents[JsonCardRes.real_name]) then - cardList[JsonCardRes.code].permanent = true - else - cardList[JsonCardRes.code].permanent = false - end - else - cardList[JsonCardRes.code].permanent = false - end - - -- Check for '1:3' bonding cards, which always brings in 3 bonded cards, where the original card is limit 1 per deck. - for k,v in pairs(bondedCardsOneThree) do - if (v.name == JsonCardRes.real_name) - then - - -- Check for Miss Doyle, who has a special exception since her 3 cards are different - if (v.name == "Miss Doyle") - then - local row = {} - local rowSecond = {} - local rowThird = {} - row.cardName = v.bondedName - rowSecond.cardName = v.bondedNameSecond - rowThird.cardName = v.bondedNameThird - row.cardCount = 1 - rowSecond.cardCount = 1 - rowThird.cardCount = 1 - row.permanent = true - rowSecond.permanent = true - rowThird.permanent = true - cardList[v.bondedCode] = row - cardList[v.bondedCodeSecond] = rowSecond - cardList[v.bondedCodeThird] = rowThird - else - local row = {} - row.cardName = v.bondedName - row.cardCount = 3 - row.permanent = true - cardList[v.bondedCode] = row - end - end - end - - -- Check for more complicated bonding cards - for k,v in pairs(bondedCardsBoolean) do - if (v.name == JsonCardRes.real_name and cardList[v.bondedCode] == nil) - then - local row = {} - row.cardName = v.bondedName - row.cardCount = v.bondCount - row.permanent = true - cardList[v.bondedCode] = row - end - end - - - -- Check for Taboos (add " (Taboo)" to card name) - if tabooID then - for k,v in pairs(tabooList[tabooID].cards) do - if v.code == JsonCardRes.code - then - cardList[JsonCardRes.code].cardName = cardList[JsonCardRes.code].cardName .. " (Taboo)" - end - end - end - - -- Update number of processed slots, if complete, start building the deck - doneSlots = doneSlots + 1 - if (doneSlots == numSlots) - then - createDeck() - end -end - -function tabooListCallback(req) - -- Result check.. - if req.is_done and not req.is_error - then - -- Find unicode before using JSON.decode since it doesnt handle hex UTF-16 - local tmpText = string.gsub(req.text,"\\u(%w%w%w%w)", convertHexToDec) - JsonTabooRes = JSON.decode(tmpText) - else - print(req.error) - return - end - for k,v in pairs(JsonTabooRes) do - local row = {} - row.date = v.date_start - row.cards = JSON.decode(v.cards) - tabooList[v.id] = row - end -end - -function createDeck() - -- Create clone of playerCardDeck to use for drawing cards - local cloneParams = {} - cloneParams.position = {0,0,50} - tmpDeck = playerCardDeck.clone(cloneParams) - - for k,v in pairs(cardList) do - searchForCard(v.cardName, v.subName, v.cardCount, v.permanent) - end - - tmpDeck.destruct() -end - -function searchForCard(cardName, subName, cardCount, permanent) - if cardName == 'Random Basic Weakness' and weaknessDeck then - -- pull a weakness card instead - weaknessDeck.shuffle() - local taken = weaknessDeck.takeObject({ - position = deckPos, - index = 0, - smooth = false, - params = { cardName, cardCount, false } - }) - -- just special case the one permanent for now - if taken.getName() == 'Indebted' then - taken.setPosition(permPos) - end - broadcastToAll("Drew random basic weakness: " .. taken.getName()) - return - end - allCards = tmpDeck.getObjects() - for k,v in pairs(allCards) do - if (v.nickname == cardName) - then - if(subName == nil or v.description == subName) - then - tmpDeck.takeObject({ - position = {10, 0, 20}, - callback = 'cardTaken', - callback_owner=self, - index = v.index, - smooth = false, - params = { cardName, cardCount, permanent, v.guid } - }) - print('Added '.. cardCount .. ' of ' .. cardName) - return - end - end - end - broadcastToAll("Card not found: "..cardName, {0.5,0.5,0.5}) -end - -function cardTaken(card, params) - -- Check destination deck (permanent?) - local destPos - if (params[3] == true) then -- permanent card - destPos = permPos - else - destPos = deckPos - end - - if (card.getName() == params[1]) then - for i=1,params[2]-1,1 do - local cloneParams = {} - cloneParams.position=destPos - card.clone(cloneParams) - end - card.setPosition(destPos) - else - print('Wrong card: ' .. card.getName()) - tmpDeck.putObject(card) - end -end - -function makeText() - -- Create textbox - local input_parameters = {} - input_parameters.input_function = "inputTyped" - input_parameters.function_owner = self - input_parameters.position = {0.8,0.2,-0.3} - input_parameters.width = 2220 - input_parameters.scale = {0.1,0.1,0.1} - input_parameters.height = 600 - input_parameters.font_size = 500 - input_parameters.tooltip = "*****PLEASE USE AN UNPUBLISHED DECK IF JUST FOR TTS TO AVOID FLOODING ARKHAMDB PUBLISHED DECK LISTS!*****\nInput deck ID from ArkhamDB URL of the deck\nExample: For the URL 'https://arkhamdb.com/decklist/view/101/knowledge-overwhelming-solo-deck-1.0', you should input '101'" - input_parameters.alignment = 3 -- (1 = Automatic, 2 = Left, 3 = Center, 4 = Right, 5 = Justified) –Optional - input_parameters.value="" - tile.createInput(input_parameters) -end - -function makeButton() - -- Create Button - local button_parameters = {} - button_parameters.click_function = "buttonClicked" - button_parameters.function_owner = self - button_parameters.position = {-0.26,0.1,0.37} - button_parameters.width = 300 - button_parameters.height = 4 - button_parameters.tooltip = "Click to build your deck!" - tile.createButton(button_parameters) -end - -function makeCheckboxPP() - local checkbox_parameters = {} - checkbox_parameters.click_function = "checkboxPPClicked" - checkbox_parameters.function_owner = self - checkbox_parameters.position = {-0.8,0.2,-0.3} - checkbox_parameters.width = 2600 - checkbox_parameters.height = 500 - checkbox_parameters.tooltip = "Click to toggle Private/Published deck ID" - checkbox_parameters.label = "Private deck" - checkbox_parameters.font_size = 350 - checkbox_parameters.scale = {0.1,0.1,0.1} - tile.createButton(checkbox_parameters) -end - -function makeCheckboxPerms() - local checkbox_parameters = {} - checkbox_parameters.click_function = "checkboxPermsClicked" - checkbox_parameters.function_owner = self - checkbox_parameters.position = {-0.2,0.2,-0.3} - checkbox_parameters.width = 2200 - checkbox_parameters.height = 500 - checkbox_parameters.tooltip = "Click to toggle separate permanents" - checkbox_parameters.label = "Permanents" - checkbox_parameters.font_size = 350 - checkbox_parameters.scale = {0.1,0.1,0.1} - tile.createButton(checkbox_parameters) -end - --- Function to convert utf-16 hex to actual character since JSON.decode doesn't seem to handle utf-16 hex very well.. -function convertHexToDec(a) - return string.char(tonumber(a,16)) -end --------------- --------------- --- Start of Dzikakulka's positioning script - - --- Return position "position" in "object"'s frame of reference --- (most likely the only function you want to directly access) -function LocalPos(object, position) - local rot = object.getRotation() - local lPos = {position[1], position[2], position[3]} - - -- Z-X-Y extrinsic - local zRot = RotMatrix('z', rot['z']) - lPos = RotateVector(zRot, lPos) - local xRot = RotMatrix('x', rot['x']) - lPos = RotateVector(xRot, lPos) - local yRot = RotMatrix('y', rot['y']) - lPos = RotateVector(yRot, lPos) - - return Vect_Sum(lPos, object.getPosition()) -end - --- Build rotation matrix --- 1st table = 1st row, 2nd table = 2nd row etc -function RotMatrix(axis, angDeg) - local ang = math.rad(angDeg) - local cs = math.cos - local sn = math.sin - - if axis == 'x' then - return { - { 1, 0, 0 }, - { 0, cs(ang), -1*sn(ang) }, - { 0, sn(ang), cs(ang) } - } - elseif axis == 'y' then - return { - { cs(ang), 0, sn(ang) }, - { 0, 1, 0 }, - { -1*sn(ang), 0, cs(ang) } - } - elseif axis == 'z' then - return { - { cs(ang), -1*sn(ang), 0 }, - { sn(ang), cs(ang), 0 }, - { 0, 0, 1 } - } - end -end - --- Apply given rotation matrix on given vector --- (multiply matrix and column vector) -function RotateVector(rotMat, vect) - local out = {0, 0, 0} - for i=1,3,1 do - for j=1,3,1 do - out[i] = out[i] + rotMat[i][j]*vect[j] - end - end - return out -end - --- Sum of two vectors (of any size) -function Vect_Sum(vec1, vec2) - local out = {} - local k = 1 - while vec1[k] ~= nil and vec2[k] ~= nil do - out[k] = vec1[k] + vec2[k] - k = k+1 - end - return out -end - --- End Dzikakulka's positioning script - - -function inputTyped(objectInputTyped, playerColorTyped, input_value, selected) - deckID = input_value -end - ---[[ The onUpdate event is called once per frame. --]] -function onUpdate () - --[[ print('onUpdate loop!') --]] +--[[ Lua code. See documentation: http://berserk-games.com/knowledgebase/scripting/ --]] + +--[[ The onLoad event is called after the game save finishes loading. --]] +function onLoad() + --[[ print('onLoad!') --]] + init() + -- Setup... + publicDeckURL="https://arkhamdb.com/api/public/decklist/" + privateDeckURL="https://arkhamdb.com/api/public/deck/" + cardURL="https://arkhamdb.com/api/public/card/" + tabooListURL="https://arkhamdb.com/api/public/taboos/" + subnameCards={{name="Randolph Carter",xp=0},{name="Dream Diary",xp=3},{name="Relic of Ages",xp=0},{name="The Necronomicon",xp=0},{name="Archaic Glyphs",xp=3},{name="Strange Solution",xp=4},{name="Forbidden Tome",xp=3},{name="Relic of Ages",xp=0}, {name="Ancient Stone",xp=4}, {"Dream Diary",xp=0},{name="Empower Self",xp=2}} + extraPermanents={["Duke"]=true,["Sophie"]=true,["Gate Box"]=true,["Dark Insight"]=true} + multiClassCards={{name=".45 Thompson",xp=3},{name="Scroll of Secrets",xp=3},{name="Tennessee Sour Mash",xp=3},{name="Enchanted Blade",xp=3},{name="Grisly Totem",xp=3}} + returningCards={{name="On Your Own"}} + advancedSignatures={{name="Daisy's Tote Bag"},{name="The Necronomicon"},{name="On the Lam"},{name="Hospital Debts"}} + bondedCardsOneThree={{name="Hallowed Mirror",bondedName="Soothing Melody",bondedCode=05314},{name="Occult Lexicon",bondedName="Blood-Rite",bondedCode=05317},{name="The Hungering Blade",bondedName="Bloodlust",bondedCode=06019},{name="Nightmare Bauble",bondedName="Dream Parasite",bondedCode=06331},{name="Miss Doyle",bondedName="Hope",bondedCode=06031,bondedNameSecond="Zeal",bondedCodeSecond=06032,bondedNameThird="Augur",bondedCodeThird=06033}} + bondedCardsBoolean = {{name="Gate Box",bondedName="Dream-Gate",bondedCode="06015a",bondCount=1},{name="Crystallizer of Dreams",bondedName="Guardian of the Crystallizer",bondedCode=06025,bondCount=2},{name="Dream Diary",bondedName="Essence of the Dream",bondedCode=06113,bondCount=1},{name="Empty Vessel",bondedName="Wish Eater",bondedCode=06277,bondCount=1},{name="Segment of Onyx",bondedName="Pendant of the Queen",bondedCode=06022,bondCount=1},{name="Stargazing",bondedName="The Stars Are Right",bondedCode=06028,bondCount=2},{name="Summoned Hound",bondedName="Unbound Beast",bondedCode=06283,bondCount=2}} + privateDeck = true + permanents = true + + local tileGUID = '928c8e' + tile = getObjectFromGUID(tileGUID) + makeText() + makeButton() + makeCheckboxPP() + makeCheckboxPerms() + + -- Get current taboolist + tabooList = {} + WebRequest.get(tabooListURL, self, 'tabooListCallback') +end + +function spawnZone() + -- Clean up scripting zone + if pcZone then + pcZone.destruct() + end + if weaknessZone then + weaknessZone.destruct() + end + deckPos = LocalPos(self,{-1.85,1.5,1.8}) + permPos = LocalPos(self,{-4.63,1.5,1.8}) + local pcZonePos = LocalPos(self,{4.75, 2.6 , 1.8}) + zoneSpawn = {position = pcZonePos + , scale = { 10.57, 5.1, 10.47 } + , type = 'ScriptingTrigger' +-- , callback = 'zoneCallback' + , callback_owner = self + , rotation = self.getRotation() } + pcZone = spawnObject(zoneSpawn) + + -- get a scripting zone at the weakness deck + --local weaknessZonePosition = self.positionToWorld({-7.5, 2.6 , 1.8}) + local weaknessZonePosition = LocalPos(self, {-7.5, 0 , 1.8}) + weaknessZone = spawnObject({ + position = weaknessZonePosition, + type = 'ScriptingTrigger', + rotation = self.getRotation() + }) + + for i=1,1 do + coroutine.yield(0) + end + + local objectsInZone = pcZone.getObjects() + for i,v in pairs(objectsInZone) do + if v.tag == 'Deck' then + playerCardDeck = v + end + end + + local objectsInZone = weaknessZone.getObjects() + for i,v in pairs(objectsInZone) do + if v.getName() == 'All Weaknesses' then + weaknessDeck = v + end + end + + -- Get deck from ArkhamDB.. + local deckURL + if privateDeck then deckURL = privateDeckURL + else deckURL = publicDeckURL + end + + WebRequest.get(deckURL .. deckID, self, 'deckReadCallback') + + return 1 +end + +function init() + cardList = {} + doneSlots = 0 + playerCardDeck = {} + weaknessDeck = {} + totalCards = 0 + tabooID = 0 +end + +function buttonClicked() + -- Reset + init() + -- Spawn scripting zone + startLuaCoroutine(self, "spawnZone") +end + +function checkboxPPClicked() + buttons = tile.getButtons() + for k,v in pairs(buttons) do + if (v.label == "Private deck") then + local button_parameters = {} + button_parameters.label = "Published deck" + button_parameters.index = v.index + tile.editButton(button_parameters) + privateDeck = false + else + if (v.label == "Published deck") then + local button_parameters = {} + button_parameters.label = "Private deck" + button_parameters.index = v.index + tile.editButton(button_parameters) + privateDeck = true + end + end + end +end + +function checkboxPermsClicked() + buttons = tile.getButtons() + for k,v in pairs(buttons) do + if (v.label == "Permanents") then + local button_parameters = {} + button_parameters.label = "No permanents" + button_parameters.index = v.index + tile.editButton(button_parameters) + permanents = false + else + if (v.label == "No permanents") then + local button_parameters = {} + button_parameters.label = "Permanents" + button_parameters.index = v.index + tile.editButton(button_parameters) + permanents = true + end + end + end +end + +function deckReadCallback(req) + -- Result check.. + if req.is_done and not req.is_error + then + if string.find(req.text, "") + then + broadcastToAll("Private deck "..deckID.." is not shared", {0.5,0.5,0.5}) + return + end + JsonDeckRes = JSON.decode(req.text) + else + print (req.error) + return + end + if (JsonDeckRes == nil) + then + broadcastToAll("Deck not found!", {0.5,0.5,0.5}) + return + else + print("Found decklist: "..JsonDeckRes.name) + end + -- Count number of cards in decklist + numSlots=0 + for cardid,number in + pairs(JsonDeckRes.slots) + do + numSlots = numSlots + 1 + end + + -- Check for taboos + tabooID = JsonDeckRes.taboo_id + if tabooID + then + print("Using List of Taboos from "..tabooList[tabooID].date..".") + end + + -- Save card id, number in table and request card info from ArkhamDB + for cardID,number in pairs(JsonDeckRes.slots) + do + local row = {} + row.cardName = "" + row.cardCount = number + cardList[cardID] = row + WebRequest.get(cardURL .. cardID, self, 'cardReadCallback') + totalCards = totalCards + number + end +end + +function cardReadCallback(req) + -- Result check.. + if req.is_done and not req.is_error + then + -- Find unicode before using JSON.decode since it doesnt handle hex UTF-16 + local tmpText = string.gsub(req.text,"\\u(%w%w%w%w)", convertHexToDec) + JsonCardRes = JSON.decode(tmpText) + else + print(req.error) + return + end + + -- Update card name in table + if(JsonCardRes.xp == nil or JsonCardRes.xp == 0) + then + cardList[JsonCardRes.code].cardName = JsonCardRes.real_name + else + cardList[JsonCardRes.code].cardName = JsonCardRes.real_name .. " (" .. JsonCardRes.xp .. ")" + end + + -- Make Subname blank if it does not exist + if (JsonCardRes.subname == nil and (JsonCardRes.subtype_name ~= "Basic Weakness" and JsonCardRes.subtype_name ~= "Weakness")) + then + cardList[JsonCardRes.code].subName = "" + end + + -- Check for subname + for k,v in pairs(subnameCards) do + if (v.name == JsonCardRes.real_name and (v.xp == JsonCardRes.xp or JsonCardRes.xp == nil)) + then + cardList[JsonCardRes.code].subName = JsonCardRes.subname + end + end + + -- Check for multiclass + for k,v in pairs(multiClassCards) do + if (v.name == JsonCardRes.real_name and (v.xp == JsonCardRes.xp or JsonCardRes.xp == nil)) + then + cardList[JsonCardRes.code].subName = JsonCardRes.faction_name + end + end + + -- Check for returning cards (cards with the same name/level but different and from a new set) + for k,v in pairs(returningCards) do + if (v.name == JsonCardRes.real_name and JsonCardRes.pack_name == "Return to the Forgotten Age") + then + cardList[JsonCardRes.code].subName = "Permanent" + end + end + + -- Check for advanced signature cards (this happens after subname check, so it should be fine) + for k,v in pairs(advancedSignatures) do + if (v.name == JsonCardRes.real_name) + then + if (JsonCardRes.pack_name == "Read or Die" or JsonCardRes.pack_name == "All or Nothing") + then + if (v.name == "The Necronomicon") + then + cardList[JsonCardRes.code].subName = "John Dee Translation (Advanced)" + else + cardList[JsonCardRes.code].subName = "Advanced" + end + end + end + end + + -- Check if card is permanent (if separation is selected) + if permanents then + if (JsonCardRes.permanent == true or extraPermanents[JsonCardRes.real_name]) then + cardList[JsonCardRes.code].permanent = true + else + cardList[JsonCardRes.code].permanent = false + end + else + cardList[JsonCardRes.code].permanent = false + end + + -- Check for '1:3' bonding cards, which always brings in 3 bonded cards, where the original card is limit 1 per deck. + for k,v in pairs(bondedCardsOneThree) do + if (v.name == JsonCardRes.real_name) + then + + -- Check for Miss Doyle, who has a special exception since her 3 cards are different + if (v.name == "Miss Doyle") + then + local row = {} + local rowSecond = {} + local rowThird = {} + row.cardName = v.bondedName + rowSecond.cardName = v.bondedNameSecond + rowThird.cardName = v.bondedNameThird + row.cardCount = 1 + rowSecond.cardCount = 1 + rowThird.cardCount = 1 + row.permanent = true + rowSecond.permanent = true + rowThird.permanent = true + cardList[v.bondedCode] = row + cardList[v.bondedCodeSecond] = rowSecond + cardList[v.bondedCodeThird] = rowThird + else + local row = {} + row.cardName = v.bondedName + row.cardCount = 3 + row.permanent = true + cardList[v.bondedCode] = row + end + end + end + + -- Check for more complicated bonding cards + for k,v in pairs(bondedCardsBoolean) do + if (v.name == JsonCardRes.real_name and cardList[v.bondedCode] == nil) + then + local row = {} + row.cardName = v.bondedName + row.cardCount = v.bondCount + row.permanent = true + cardList[v.bondedCode] = row + end + end + + + -- Check for Taboos (add " (Taboo)" to card name) + if tabooID then + for k,v in pairs(tabooList[tabooID].cards) do + if v.code == JsonCardRes.code + then + cardList[JsonCardRes.code].cardName = cardList[JsonCardRes.code].cardName .. " (Taboo)" + end + end + end + + -- Update number of processed slots, if complete, start building the deck + doneSlots = doneSlots + 1 + if (doneSlots == numSlots) + then + createDeck() + end +end + +function tabooListCallback(req) + -- Result check.. + if req.is_done and not req.is_error + then + -- Find unicode before using JSON.decode since it doesnt handle hex UTF-16 + local tmpText = string.gsub(req.text,"\\u(%w%w%w%w)", convertHexToDec) + JsonTabooRes = JSON.decode(tmpText) + else + print(req.error) + return + end + for k,v in pairs(JsonTabooRes) do + local row = {} + row.date = v.date_start + row.cards = JSON.decode(v.cards) + tabooList[v.id] = row + end +end + +function createDeck() + -- Create clone of playerCardDeck to use for drawing cards + local cloneParams = {} + cloneParams.position = {0,0,50} + tmpDeck = playerCardDeck.clone(cloneParams) + + for k,v in pairs(cardList) do + searchForCard(v.cardName, v.subName, v.cardCount, v.permanent) + end + + tmpDeck.destruct() +end + +function searchForCard(cardName, subName, cardCount, permanent) + if cardName == 'Random Basic Weakness' and weaknessDeck then + -- pull a weakness card instead + weaknessDeck.shuffle() + local taken = weaknessDeck.takeObject({ + position = deckPos, + index = 0, + smooth = false, + params = { cardName, cardCount, false } + }) + -- just special case the one permanent for now + if taken.getName() == 'Indebted' then + taken.setPosition(permPos) + end + broadcastToAll("Drew random basic weakness: " .. taken.getName()) + return + end + allCards = tmpDeck.getObjects() + for k,v in pairs(allCards) do + if (v.nickname == cardName) + then + if(subName == nil or v.description == subName) + then + tmpDeck.takeObject({ + position = {10, 0, 20}, + callback = 'cardTaken', + callback_owner=self, + index = v.index, + smooth = false, + params = { cardName, cardCount, permanent, v.guid } + }) + print('Added '.. cardCount .. ' of ' .. cardName) + return + end + end + end + broadcastToAll("Card not found: "..cardName, {0.5,0.5,0.5}) +end + +function cardTaken(card, params) + -- Check destination deck (permanent?) + local destPos + if (params[3] == true) then -- permanent card + destPos = permPos + else + destPos = deckPos + end + + if (card.getName() == params[1]) then + for i=1,params[2]-1,1 do + local cloneParams = {} + cloneParams.position=destPos + card.clone(cloneParams) + end + card.setPosition(destPos) + else + print('Wrong card: ' .. card.getName()) + tmpDeck.putObject(card) + end +end + +function makeText() + -- Create textbox + local input_parameters = {} + input_parameters.input_function = "inputTyped" + input_parameters.function_owner = self + input_parameters.position = {0.8,0.2,-0.3} + input_parameters.width = 2220 + input_parameters.scale = {0.1,0.1,0.1} + input_parameters.height = 600 + input_parameters.font_size = 500 + input_parameters.tooltip = "*****PLEASE USE AN UNPUBLISHED DECK IF JUST FOR TTS TO AVOID FLOODING ARKHAMDB PUBLISHED DECK LISTS!*****\nInput deck ID from ArkhamDB URL of the deck\nExample: For the URL 'https://arkhamdb.com/decklist/view/101/knowledge-overwhelming-solo-deck-1.0', you should input '101'" + input_parameters.alignment = 3 -- (1 = Automatic, 2 = Left, 3 = Center, 4 = Right, 5 = Justified) –Optional + input_parameters.value="" + tile.createInput(input_parameters) +end + +function makeButton() + -- Create Button + local button_parameters = {} + button_parameters.click_function = "buttonClicked" + button_parameters.function_owner = self + button_parameters.position = {-0.26,0.1,0.37} + button_parameters.width = 300 + button_parameters.height = 4 + button_parameters.tooltip = "Click to build your deck!" + tile.createButton(button_parameters) +end + +function makeCheckboxPP() + local checkbox_parameters = {} + checkbox_parameters.click_function = "checkboxPPClicked" + checkbox_parameters.function_owner = self + checkbox_parameters.position = {-0.8,0.2,-0.3} + checkbox_parameters.width = 2600 + checkbox_parameters.height = 500 + checkbox_parameters.tooltip = "Click to toggle Private/Published deck ID" + checkbox_parameters.label = "Private deck" + checkbox_parameters.font_size = 350 + checkbox_parameters.scale = {0.1,0.1,0.1} + tile.createButton(checkbox_parameters) +end + +function makeCheckboxPerms() + local checkbox_parameters = {} + checkbox_parameters.click_function = "checkboxPermsClicked" + checkbox_parameters.function_owner = self + checkbox_parameters.position = {-0.2,0.2,-0.3} + checkbox_parameters.width = 2200 + checkbox_parameters.height = 500 + checkbox_parameters.tooltip = "Click to toggle separate permanents" + checkbox_parameters.label = "Permanents" + checkbox_parameters.font_size = 350 + checkbox_parameters.scale = {0.1,0.1,0.1} + tile.createButton(checkbox_parameters) +end + +-- Function to convert utf-16 hex to actual character since JSON.decode doesn't seem to handle utf-16 hex very well.. +function convertHexToDec(a) + return string.char(tonumber(a,16)) +end +-------------- +-------------- +-- Start of Dzikakulka's positioning script + + +-- Return position "position" in "object"'s frame of reference +-- (most likely the only function you want to directly access) +function LocalPos(object, position) + local rot = object.getRotation() + local lPos = {position[1], position[2], position[3]} + + -- Z-X-Y extrinsic + local zRot = RotMatrix('z', rot['z']) + lPos = RotateVector(zRot, lPos) + local xRot = RotMatrix('x', rot['x']) + lPos = RotateVector(xRot, lPos) + local yRot = RotMatrix('y', rot['y']) + lPos = RotateVector(yRot, lPos) + + return Vect_Sum(lPos, object.getPosition()) +end + +-- Build rotation matrix +-- 1st table = 1st row, 2nd table = 2nd row etc +function RotMatrix(axis, angDeg) + local ang = math.rad(angDeg) + local cs = math.cos + local sn = math.sin + + if axis == 'x' then + return { + { 1, 0, 0 }, + { 0, cs(ang), -1*sn(ang) }, + { 0, sn(ang), cs(ang) } + } + elseif axis == 'y' then + return { + { cs(ang), 0, sn(ang) }, + { 0, 1, 0 }, + { -1*sn(ang), 0, cs(ang) } + } + elseif axis == 'z' then + return { + { cs(ang), -1*sn(ang), 0 }, + { sn(ang), cs(ang), 0 }, + { 0, 0, 1 } + } + end +end + +-- Apply given rotation matrix on given vector +-- (multiply matrix and column vector) +function RotateVector(rotMat, vect) + local out = {0, 0, 0} + for i=1,3,1 do + for j=1,3,1 do + out[i] = out[i] + rotMat[i][j]*vect[j] + end + end + return out +end + +-- Sum of two vectors (of any size) +function Vect_Sum(vec1, vec2) + local out = {} + local k = 1 + while vec1[k] ~= nil and vec2[k] ~= nil do + out[k] = vec1[k] + vec2[k] + k = k+1 + end + return out +end + +-- End Dzikakulka's positioning script + + +function inputTyped(objectInputTyped, playerColorTyped, input_value, selected) + deckID = input_value +end + +--[[ The onUpdate event is called once per frame. --]] +function onUpdate () + --[[ print('onUpdate loop!') --]] end \ No newline at end of file diff --git a/unpacked/Custom_Tile Playermat 1 White 8b081b.ttslua b/unpacked/Custom_Tile Playermat 1 White 8b081b.ttslua index 4f610fbae..b49bf41d4 100644 --- a/unpacked/Custom_Tile Playermat 1 White 8b081b.ttslua +++ b/unpacked/Custom_Tile Playermat 1 White 8b081b.ttslua @@ -1,405 +1,405 @@ --- set true to enable debug logging -DEBUG = false --- we use this to turn off collision handling (for clue spawning) --- until after load is complete (probably a better way to do this) -COLLISION_ENABLED = false --- position offsets, adjust these to reposition things relative to mat [x,y,z] -DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} -DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} -DISCARD_BUTTON_OFFSETS = { - {-0.98, 0.2, -0.945}, - {-0.525, 0.2, -0.945}, - {-0.07, 0.2, -0.945}, - {0.39, 0.2, -0.945}, - {0.84, 0.2, -0.945}, -} --- draw deck and discard zone -DECK_POSITION = { x=-1.4, y=0, z=0.3 } -DECK_ZONE_SCALE = { x=3, y=5, z=8 } -DRAW_DECK_POSITION = { x=-55, y=2.5, z=4.5 } - --- play zone -PLAYER_COLOR = "White" -PLAY_ZONE_POSITION = { x=-55, y=4, z=17 } -PLAY_ZONE_ROTATION = { x=0, y=270, z=0 } -PLAY_ZONE_SCALE = { x=30, y=5, z=15 } - -RESOURCE_COUNTER_GUID = "4406f0" - --- the position of the global discard pile --- TODO: delegate to global for any auto discard actions -DISCARD_POSITION = {-3.85, 3, 10.38} - -function log(message) - if DEBUG then - print(message) - end -end - --- builds a function that discards things in searchPostion to discardPostition -function makeDiscardHandlerFor(searchPosition, discardPosition) - return function (_) - local discardItemList = findObjectsAtPosition(searchPosition) - for _, obj in ipairs(discardItemList) do - obj.setPositionSmooth(discardPosition, false, true) - obj.setRotation({0, -90, 0}) - end - end -end - --- build a discard button at position to discard from searchPosition to discardPosition --- number must be unique -function makeDiscardButton(position, searchPosition, discardPosition, number) - local handler = makeDiscardHandlerFor(searchPosition, discardPosition) - local handlerName = 'handler' .. number - self.setVar(handlerName, handler) - self.createButton({ - label = "Discard", - click_function= handlerName, - function_owner= self, - position = position, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180, - }) -end - -function onload(save_state) - self.interactable = DEBUG - DATA_HELPER = getObjectFromGUID('708279') - PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') - PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') - - -- positions of encounter card slots - local encounterSlots = { - {1, 0, -0.7}, - {0.55, 0, -0.7}, - {0.1, 0, -0.7}, - {-0.35, 0, -0.7}, - {-0.8, 0, -0.7} - } - - local i = 1 - while i <= 5 do - makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) - i = i + 1 - end - - self.createButton({ - label = " ", - click_function = "drawEncountercard", - function_owner = self, - position = {-1.45,0,-0.7}, - rotation = {0,-15,0}, - width = 170, - height = 255, - font_size = 50 - }) - - self.createButton({ - label=" ", - click_function = "drawChaostokenButton", - function_owner = self, - position = {1.48,0.0,-0.74}, - rotation = {0,-45,0}, - width = 125, - height = 125, - font_size = 50 - }) - - self.createButton({ - label="Upkeep", - click_function = "doUpkeep", - function_owner = self, - position = {1.48,0.1,-0.4}, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180 - }) - - local state = JSON.decode(save_state) - if state ~= nil and state.zoneID ~= nil then - zoneID = state.zoneID - Wait.time(checkDeckZoneExists, 30) - else - spawnDeckZone() - end - - COLLISION_ENABLED = true -end - -function onSave() - return JSON.encode({ zoneID=zoneID }) -end - -function doUpkeep(obj, color, alt_click) - -- right-click binds to new player color - if alt_click then - PLAYER_COLOR = color - printToColor("Upkeep button bound to " .. color, color) - return - end - - -- unexhaust cards in play zone - local objs = Physics.cast({ - origin = PLAY_ZONE_POSITION, - direction = { x=0, y=1, z=0 }, - type = 3, - size = PLAY_ZONE_SCALE, - orientation = PLAY_ZONE_ROTATION - }) - - local y = PLAY_ZONE_ROTATION.y - - local investigator = nil - for i,v in ipairs(objs) do - local obj = v.hit_object - local props = obj.getCustomObject() - if obj.tag == "Card" and not obj.is_face_down then - if props ~= nil and props.unique_back then - local name = obj.getName() - if string.match(name, "Jenny Barnes") ~= nil then - investigator = "Jenny Barnes" - elseif name == "Patrice Hathaway" then - investigator = name - end - else - local r = obj.getRotation() - if (r.y - y > 10) or (y - r.y > 10) then - obj.setRotationSmooth(PLAY_ZONE_ROTATION) - end - end - end - end - - -- gain resource - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - if investigator == "Jenny Barnes" then - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) - end - - -- draw card (shuffle discard if necessary) - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - drawDeck = nil - discardPile = nil - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Deck" or object.tag == "Card" then - if object.is_face_down then - drawDeck = object - else - discardPile = object - end - end - end - - if investigator == "Patrice Hathaway" then - patriceDraw() - return - end - - if drawDeck == nil then - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(1), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) - else - drawCards(1) - end -end - -function drawCards(numCards) - if drawDeck == nil then return end - drawDeck.deal(numCards, PLAYER_COLOR) -end - -function shuffleDiscardIntoDeck() - discardPile.flip() - discardPile.shuffle() - discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) - drawDeck = discardPile - discardPile = nil -end - -function patriceDraw() - local handSize = #Player[PLAYER_COLOR].getHandObjects() - if handSize >= 5 then return end - local cardsToDraw = 5 - handSize - local deckSize - printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) - if drawDeck == nil then - deckSize = 0 - elseif drawDeck.tag == "Deck" then - deckSize = #drawDeck.getObjects() - else - deckSize = 1 - end - - if deckSize >= cardsToDraw then - drawCards(cardsToDraw) - return - end - - drawCards(deckSize) - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(cardsToDraw - deckSize), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) -end - -function checkDeckZoneExists() - if getObjectFromGUID(zoneID) ~= nil then return end - spawnDeckZone() -end - -function spawnDeckZone() - local pos = self.positionToWorld(DECK_POSITION) - local zoneProps = { - position = pos, - scale = DECK_ZONE_SCALE, - type = 'ScriptingTrigger', - callback = 'zoneCallback', - callback_owner = self, - rotation = self.getRotation() - } - spawnObject(zoneProps) -end - -function zoneCallback(zone) - zoneID = zone.getGUID() -end - -function findObjectsAtPosition(localPos) - local globalPos = self.positionToWorld(localPos) - local objList = Physics.cast({ - origin=globalPos, --Where the cast takes place - direction={0,1,0}, --Which direction it moves (up is shown) - type=2, --Type. 2 is "sphere" - size={2,2,2}, --How large that sphere is - max_distance=1, --How far it moves. Just a little bit - debug=false --If it displays the sphere when casting. - }) - local decksAndCards = {} - for _, obj in ipairs(objList) do - if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then - table.insert(decksAndCards, obj.hit_object) - end - end - return decksAndCards -end - -function spawnTokenOn(object, offsets, tokenType) - local tokenPosition = object.positionToWorld(offsets) - spawnToken(tokenPosition, tokenType) -end - --- spawn a group of tokens of the given type on the object -function spawnTokenGroup(object, tokenType, tokenCount) - local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] - if offsets == nil then - error("couldn't find offsets for " .. tokenCount .. ' tokens') - end - local i = 0 - while i < tokenCount do - local offset = offsets[i + 1] - spawnTokenOn(object, offset, tokenType) - i = i + 1 - end -end - -function buildPlayerCardKey(object) - return object.getName() .. ':' .. object.getDescription() -end - -function getPlayerCardData(object) - return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] -end - -function shouldSpawnTokens(object) - -- we assume we shouldn't spawn tokens if in doubt, this should - -- only ever happen on load and in that case prevents respawns - local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) - local canSpawn = getPlayerCardData(object) - return not spawned and canSpawn -end - -function markSpawned(object) - local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) - if not saved then - error('attempt to mark player card spawned before data loaded') - end -end - -function spawnTokensFor(object) - local data = getPlayerCardData(object) - if data == nil then - error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') - end - log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) - spawnTokenGroup(object, data['tokenType'], data['tokenCount']) - markSpawned(object) -end - -function resetSpawnState() - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Card" then - local guid = object.getGUID() - if guid ~= nil then unmarkSpawned(guid, true) end - elseif object.tag == "Deck" then - local cards = object.getObjects() - if (cards ~= nil) then - for i,v in ipairs(cards) do - if v.guid ~= nil then unmarkSpawned(v.guid) end - end - end - end - end -end - -function unmarkSpawned(guid, force) - if not force and getObjectFromGUID(guid) ~= nil then return end - DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) -end - -function onCollisionEnter(collision_info) - if not COLLISION_ENABLED then - return - end - - local object = collision_info.collision_object - Wait.time(resetSpawnState, 1) - -- anything to the left of this is legal to spawn - local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) - local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) - if boundaryLocalToCard.x > 0 then - log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) - return - end - if not object.is_face_down and shouldSpawnTokens(object) then - spawnTokensFor(object) - end -end - --- functions delegated to Global -function drawChaostokenButton(object, player, isRightClick) - -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) - Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) -end - -function drawEncountercard(object, player, isRightClick) -local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) -Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) -end - -function spawnToken(position, tokenType) - Global.call('spawnToken', {position, tokenType}) +-- set true to enable debug logging +DEBUG = false +-- we use this to turn off collision handling (for clue spawning) +-- until after load is complete (probably a better way to do this) +COLLISION_ENABLED = false +-- position offsets, adjust these to reposition things relative to mat [x,y,z] +DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} +DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} +DISCARD_BUTTON_OFFSETS = { + {-0.98, 0.2, -0.945}, + {-0.525, 0.2, -0.945}, + {-0.07, 0.2, -0.945}, + {0.39, 0.2, -0.945}, + {0.84, 0.2, -0.945}, +} +-- draw deck and discard zone +DECK_POSITION = { x=-1.4, y=0, z=0.3 } +DECK_ZONE_SCALE = { x=3, y=5, z=8 } +DRAW_DECK_POSITION = { x=-55, y=2.5, z=4.5 } + +-- play zone +PLAYER_COLOR = "White" +PLAY_ZONE_POSITION = { x=-55, y=4, z=17 } +PLAY_ZONE_ROTATION = { x=0, y=270, z=0 } +PLAY_ZONE_SCALE = { x=30, y=5, z=15 } + +RESOURCE_COUNTER_GUID = "4406f0" + +-- the position of the global discard pile +-- TODO: delegate to global for any auto discard actions +DISCARD_POSITION = {-3.85, 3, 10.38} + +function log(message) + if DEBUG then + print(message) + end +end + +-- builds a function that discards things in searchPostion to discardPostition +function makeDiscardHandlerFor(searchPosition, discardPosition) + return function (_) + local discardItemList = findObjectsAtPosition(searchPosition) + for _, obj in ipairs(discardItemList) do + obj.setPositionSmooth(discardPosition, false, true) + obj.setRotation({0, -90, 0}) + end + end +end + +-- build a discard button at position to discard from searchPosition to discardPosition +-- number must be unique +function makeDiscardButton(position, searchPosition, discardPosition, number) + local handler = makeDiscardHandlerFor(searchPosition, discardPosition) + local handlerName = 'handler' .. number + self.setVar(handlerName, handler) + self.createButton({ + label = "Discard", + click_function= handlerName, + function_owner= self, + position = position, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180, + }) +end + +function onload(save_state) + self.interactable = DEBUG + DATA_HELPER = getObjectFromGUID('708279') + PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') + PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') + + -- positions of encounter card slots + local encounterSlots = { + {1, 0, -0.7}, + {0.55, 0, -0.7}, + {0.1, 0, -0.7}, + {-0.35, 0, -0.7}, + {-0.8, 0, -0.7} + } + + local i = 1 + while i <= 5 do + makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) + i = i + 1 + end + + self.createButton({ + label = " ", + click_function = "drawEncountercard", + function_owner = self, + position = {-1.45,0,-0.7}, + rotation = {0,-15,0}, + width = 170, + height = 255, + font_size = 50 + }) + + self.createButton({ + label=" ", + click_function = "drawChaostokenButton", + function_owner = self, + position = {1.48,0.0,-0.74}, + rotation = {0,-45,0}, + width = 125, + height = 125, + font_size = 50 + }) + + self.createButton({ + label="Upkeep", + click_function = "doUpkeep", + function_owner = self, + position = {1.48,0.1,-0.4}, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180 + }) + + local state = JSON.decode(save_state) + if state ~= nil and state.zoneID ~= nil then + zoneID = state.zoneID + Wait.time(checkDeckZoneExists, 30) + else + spawnDeckZone() + end + + COLLISION_ENABLED = true +end + +function onSave() + return JSON.encode({ zoneID=zoneID }) +end + +function doUpkeep(obj, color, alt_click) + -- right-click binds to new player color + if alt_click then + PLAYER_COLOR = color + printToColor("Upkeep button bound to " .. color, color) + return + end + + -- unexhaust cards in play zone + local objs = Physics.cast({ + origin = PLAY_ZONE_POSITION, + direction = { x=0, y=1, z=0 }, + type = 3, + size = PLAY_ZONE_SCALE, + orientation = PLAY_ZONE_ROTATION + }) + + local y = PLAY_ZONE_ROTATION.y + + local investigator = nil + for i,v in ipairs(objs) do + local obj = v.hit_object + local props = obj.getCustomObject() + if obj.tag == "Card" and not obj.is_face_down then + if props ~= nil and props.unique_back then + local name = obj.getName() + if string.match(name, "Jenny Barnes") ~= nil then + investigator = "Jenny Barnes" + elseif name == "Patrice Hathaway" then + investigator = name + end + else + local r = obj.getRotation() + if (r.y - y > 10) or (y - r.y > 10) then + obj.setRotationSmooth(PLAY_ZONE_ROTATION) + end + end + end + end + + -- gain resource + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + if investigator == "Jenny Barnes" then + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) + end + + -- draw card (shuffle discard if necessary) + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + drawDeck = nil + discardPile = nil + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Deck" or object.tag == "Card" then + if object.is_face_down then + drawDeck = object + else + discardPile = object + end + end + end + + if investigator == "Patrice Hathaway" then + patriceDraw() + return + end + + if drawDeck == nil then + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(1), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) + else + drawCards(1) + end +end + +function drawCards(numCards) + if drawDeck == nil then return end + drawDeck.deal(numCards, PLAYER_COLOR) +end + +function shuffleDiscardIntoDeck() + discardPile.flip() + discardPile.shuffle() + discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) + drawDeck = discardPile + discardPile = nil +end + +function patriceDraw() + local handSize = #Player[PLAYER_COLOR].getHandObjects() + if handSize >= 5 then return end + local cardsToDraw = 5 - handSize + local deckSize + printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) + if drawDeck == nil then + deckSize = 0 + elseif drawDeck.tag == "Deck" then + deckSize = #drawDeck.getObjects() + else + deckSize = 1 + end + + if deckSize >= cardsToDraw then + drawCards(cardsToDraw) + return + end + + drawCards(deckSize) + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(cardsToDraw - deckSize), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) +end + +function checkDeckZoneExists() + if getObjectFromGUID(zoneID) ~= nil then return end + spawnDeckZone() +end + +function spawnDeckZone() + local pos = self.positionToWorld(DECK_POSITION) + local zoneProps = { + position = pos, + scale = DECK_ZONE_SCALE, + type = 'ScriptingTrigger', + callback = 'zoneCallback', + callback_owner = self, + rotation = self.getRotation() + } + spawnObject(zoneProps) +end + +function zoneCallback(zone) + zoneID = zone.getGUID() +end + +function findObjectsAtPosition(localPos) + local globalPos = self.positionToWorld(localPos) + local objList = Physics.cast({ + origin=globalPos, --Where the cast takes place + direction={0,1,0}, --Which direction it moves (up is shown) + type=2, --Type. 2 is "sphere" + size={2,2,2}, --How large that sphere is + max_distance=1, --How far it moves. Just a little bit + debug=false --If it displays the sphere when casting. + }) + local decksAndCards = {} + for _, obj in ipairs(objList) do + if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then + table.insert(decksAndCards, obj.hit_object) + end + end + return decksAndCards +end + +function spawnTokenOn(object, offsets, tokenType) + local tokenPosition = object.positionToWorld(offsets) + spawnToken(tokenPosition, tokenType) +end + +-- spawn a group of tokens of the given type on the object +function spawnTokenGroup(object, tokenType, tokenCount) + local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] + if offsets == nil then + error("couldn't find offsets for " .. tokenCount .. ' tokens') + end + local i = 0 + while i < tokenCount do + local offset = offsets[i + 1] + spawnTokenOn(object, offset, tokenType) + i = i + 1 + end +end + +function buildPlayerCardKey(object) + return object.getName() .. ':' .. object.getDescription() +end + +function getPlayerCardData(object) + return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] +end + +function shouldSpawnTokens(object) + -- we assume we shouldn't spawn tokens if in doubt, this should + -- only ever happen on load and in that case prevents respawns + local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) + local canSpawn = getPlayerCardData(object) + return not spawned and canSpawn +end + +function markSpawned(object) + local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) + if not saved then + error('attempt to mark player card spawned before data loaded') + end +end + +function spawnTokensFor(object) + local data = getPlayerCardData(object) + if data == nil then + error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') + end + log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) + spawnTokenGroup(object, data['tokenType'], data['tokenCount']) + markSpawned(object) +end + +function resetSpawnState() + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Card" then + local guid = object.getGUID() + if guid ~= nil then unmarkSpawned(guid, true) end + elseif object.tag == "Deck" then + local cards = object.getObjects() + if (cards ~= nil) then + for i,v in ipairs(cards) do + if v.guid ~= nil then unmarkSpawned(v.guid) end + end + end + end + end +end + +function unmarkSpawned(guid, force) + if not force and getObjectFromGUID(guid) ~= nil then return end + DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) +end + +function onCollisionEnter(collision_info) + if not COLLISION_ENABLED then + return + end + + local object = collision_info.collision_object + Wait.time(resetSpawnState, 1) + -- anything to the left of this is legal to spawn + local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) + local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) + if boundaryLocalToCard.x > 0 then + log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) + return + end + if not object.is_face_down and shouldSpawnTokens(object) then + spawnTokensFor(object) + end +end + +-- functions delegated to Global +function drawChaostokenButton(object, player, isRightClick) + -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) + Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) +end + +function drawEncountercard(object, player, isRightClick) +local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) +Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) +end + +function spawnToken(position, tokenType) + Global.call('spawnToken', {position, tokenType}) end \ No newline at end of file diff --git a/unpacked/Custom_Tile Playermat 2 Orange bd0ff4.ttslua b/unpacked/Custom_Tile Playermat 2 Orange bd0ff4.ttslua index 0079a2e11..c94483537 100644 --- a/unpacked/Custom_Tile Playermat 2 Orange bd0ff4.ttslua +++ b/unpacked/Custom_Tile Playermat 2 Orange bd0ff4.ttslua @@ -1,405 +1,405 @@ --- set true to enable debug logging -DEBUG = false --- we use this to turn off collision handling (for clue spawning) --- until after load is complete (probably a better way to do this) -COLLISION_ENABLED = false --- position offsets, adjust these to reposition things relative to mat [x,y,z] -DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} -DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} -DISCARD_BUTTON_OFFSETS = { - {-0.98, 0.2, -0.945}, - {-0.525, 0.2, -0.945}, - {-0.07, 0.2, -0.945}, - {0.39, 0.2, -0.945}, - {0.84, 0.2, -0.945}, -} --- draw deck and discard zone -DECK_POSITION = { x=-1.4, y=0, z=0.3 } -DECK_ZONE_SCALE = { x=3, y=5, z=8 } -DRAW_DECK_POSITION = { x=-55, y=2.5, z=-22.7 } - --- play zone -PLAYER_COLOR = "Orange" -PLAY_ZONE_POSITION = { x=-55, y=4, z=-17 } -PLAY_ZONE_ROTATION = { x=0, y=270, z=0 } -PLAY_ZONE_SCALE = { x=30, y=5, z=15 } - -RESOURCE_COUNTER_GUID = "816d84" - --- the position of the global discard pile --- TODO: delegate to global for any auto discard actions -DISCARD_POSITION = {-3.85, 3, 10.38} - -function log(message) - if DEBUG then - print(message) - end -end - --- builds a function that discards things in searchPostion to discardPostition -function makeDiscardHandlerFor(searchPosition, discardPosition) - return function (_) - local discardItemList = findObjectsAtPosition(searchPosition) - for _, obj in ipairs(discardItemList) do - obj.setPositionSmooth(discardPosition, false, true) - obj.setRotation({0, -90, 0}) - end - end -end - --- build a discard button at position to discard from searchPosition to discardPosition --- number must be unique -function makeDiscardButton(position, searchPosition, discardPosition, number) - local handler = makeDiscardHandlerFor(searchPosition, discardPosition) - local handlerName = 'handler' .. number - self.setVar(handlerName, handler) - self.createButton({ - label = "Discard", - click_function= handlerName, - function_owner= self, - position = position, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180, - }) -end - -function onload(save_state) - self.interactable = DEBUG - DATA_HELPER = getObjectFromGUID('708279') - PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') - PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') - - -- positions of encounter card slots - local encounterSlots = { - {1, 0, -0.7}, - {0.55, 0, -0.7}, - {0.1, 0, -0.7}, - {-0.35, 0, -0.7}, - {-0.8, 0, -0.7} - } - - local i = 1 - while i <= 5 do - makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) - i = i + 1 - end - - self.createButton({ - label = " ", - click_function = "drawEncountercard", - function_owner = self, - position = {-1.45,0,-0.7}, - rotation = {0,-15,0}, - width = 170, - height = 255, - font_size = 50 - }) - - self.createButton({ - label=" ", - click_function = "drawChaostokenButton", - function_owner = self, - position = {1.48,0.0,-0.74}, - rotation = {0,-45,0}, - width = 125, - height = 125, - font_size = 50 - }) - - self.createButton({ - label="Upkeep", - click_function = "doUpkeep", - function_owner = self, - position = {1.48,0.1,-0.4}, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180 - }) - - local state = JSON.decode(save_state) - if state ~= nil and state.zoneID ~= nil then - zoneID = state.zoneID - Wait.time(checkDeckZoneExists, 30) - else - spawnDeckZone() - end - - COLLISION_ENABLED = true -end - -function onSave() - return JSON.encode({ zoneID=zoneID }) -end - -function doUpkeep(obj, color, alt_click) - -- right-click binds to new player color - if alt_click then - PLAYER_COLOR = color - printToColor("Upkeep button bound to " .. color, color) - return - end - - -- unexhaust cards in play zone - local objs = Physics.cast({ - origin = PLAY_ZONE_POSITION, - direction = { x=0, y=1, z=0 }, - type = 3, - size = PLAY_ZONE_SCALE, - orientation = PLAY_ZONE_ROTATION - }) - - local y = PLAY_ZONE_ROTATION.y - - local investigator = nil - for i,v in ipairs(objs) do - local obj = v.hit_object - local props = obj.getCustomObject() - if obj.tag == "Card" and not obj.is_face_down then - if props ~= nil and props.unique_back then - local name = obj.getName() - if string.match(name, "Jenny Barnes") ~= nil then - investigator = "Jenny Barnes" - elseif name == "Patrice Hathaway" then - investigator = name - end - else - local r = obj.getRotation() - if (r.y - y > 10) or (y - r.y > 10) then - obj.setRotationSmooth(PLAY_ZONE_ROTATION) - end - end - end - end - - -- gain resource - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - if investigator == "Jenny Barnes" then - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) - end - - -- draw card (shuffle discard if necessary) - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - drawDeck = nil - discardPile = nil - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Deck" or object.tag == "Card" then - if object.is_face_down then - drawDeck = object - else - discardPile = object - end - end - end - - if investigator == "Patrice Hathaway" then - patriceDraw() - return - end - - if drawDeck == nil then - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(1), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) - else - drawCards(1) - end -end - -function drawCards(numCards) - if drawDeck == nil then return end - drawDeck.deal(numCards, PLAYER_COLOR) -end - -function shuffleDiscardIntoDeck() - discardPile.flip() - discardPile.shuffle() - discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) - drawDeck = discardPile - discardPile = nil -end - -function patriceDraw() - local handSize = #Player[PLAYER_COLOR].getHandObjects() - if handSize >= 5 then return end - local cardsToDraw = 5 - handSize - local deckSize - printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) - if drawDeck == nil then - deckSize = 0 - elseif drawDeck.tag == "Deck" then - deckSize = #drawDeck.getObjects() - else - deckSize = 1 - end - - if deckSize >= cardsToDraw then - drawCards(cardsToDraw) - return - end - - drawCards(deckSize) - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(cardsToDraw - deckSize), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) -end - -function checkDeckZoneExists() - if getObjectFromGUID(zoneID) ~= nil then return end - spawnDeckZone() -end - -function spawnDeckZone() - local pos = self.positionToWorld(DECK_POSITION) - local zoneProps = { - position = pos, - scale = DECK_ZONE_SCALE, - type = 'ScriptingTrigger', - callback = 'zoneCallback', - callback_owner = self, - rotation = self.getRotation() - } - spawnObject(zoneProps) -end - -function zoneCallback(zone) - zoneID = zone.getGUID() -end - -function findObjectsAtPosition(localPos) - local globalPos = self.positionToWorld(localPos) - local objList = Physics.cast({ - origin=globalPos, --Where the cast takes place - direction={0,1,0}, --Which direction it moves (up is shown) - type=2, --Type. 2 is "sphere" - size={2,2,2}, --How large that sphere is - max_distance=1, --How far it moves. Just a little bit - debug=false --If it displays the sphere when casting. - }) - local decksAndCards = {} - for _, obj in ipairs(objList) do - if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then - table.insert(decksAndCards, obj.hit_object) - end - end - return decksAndCards -end - -function spawnTokenOn(object, offsets, tokenType) - local tokenPosition = object.positionToWorld(offsets) - spawnToken(tokenPosition, tokenType) -end - --- spawn a group of tokens of the given type on the object -function spawnTokenGroup(object, tokenType, tokenCount) - local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] - if offsets == nil then - error("couldn't find offsets for " .. tokenCount .. ' tokens') - end - local i = 0 - while i < tokenCount do - local offset = offsets[i + 1] - spawnTokenOn(object, offset, tokenType) - i = i + 1 - end -end - -function buildPlayerCardKey(object) - return object.getName() .. ':' .. object.getDescription() -end - -function getPlayerCardData(object) - return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] -end - -function shouldSpawnTokens(object) - -- we assume we shouldn't spawn tokens if in doubt, this should - -- only ever happen on load and in that case prevents respawns - local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) - local canSpawn = getPlayerCardData(object) - return not spawned and canSpawn -end - -function markSpawned(object) - local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) - if not saved then - error('attempt to mark player card spawned before data loaded') - end -end - -function spawnTokensFor(object) - local data = getPlayerCardData(object) - if data == nil then - error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') - end - log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) - spawnTokenGroup(object, data['tokenType'], data['tokenCount']) - markSpawned(object) -end - -function resetSpawnState() - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Card" then - local guid = object.getGUID() - if guid ~= nil then unmarkSpawned(guid, true) end - elseif object.tag == "Deck" then - local cards = object.getObjects() - if (cards ~= nil) then - for i,v in ipairs(cards) do - if v.guid ~= nil then unmarkSpawned(v.guid) end - end - end - end - end -end - -function unmarkSpawned(guid, force) - if not force and getObjectFromGUID(guid) ~= nil then return end - DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) -end - -function onCollisionEnter(collision_info) - if not COLLISION_ENABLED then - return - end - - local object = collision_info.collision_object - Wait.time(resetSpawnState, 1) - -- anything to the left of this is legal to spawn - local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) - local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) - if boundaryLocalToCard.x > 0 then - log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) - return - end - if not object.is_face_down and shouldSpawnTokens(object) then - spawnTokensFor(object) - end -end - --- functions delegated to Global -function drawChaostokenButton(object, player, isRightClick) - -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) - Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) -end - -function drawEncountercard(object, player, isRightClick) -local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) -Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) -end - -function spawnToken(position, tokenType) - Global.call('spawnToken', {position, tokenType}) +-- set true to enable debug logging +DEBUG = false +-- we use this to turn off collision handling (for clue spawning) +-- until after load is complete (probably a better way to do this) +COLLISION_ENABLED = false +-- position offsets, adjust these to reposition things relative to mat [x,y,z] +DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} +DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} +DISCARD_BUTTON_OFFSETS = { + {-0.98, 0.2, -0.945}, + {-0.525, 0.2, -0.945}, + {-0.07, 0.2, -0.945}, + {0.39, 0.2, -0.945}, + {0.84, 0.2, -0.945}, +} +-- draw deck and discard zone +DECK_POSITION = { x=-1.4, y=0, z=0.3 } +DECK_ZONE_SCALE = { x=3, y=5, z=8 } +DRAW_DECK_POSITION = { x=-55, y=2.5, z=-22.7 } + +-- play zone +PLAYER_COLOR = "Orange" +PLAY_ZONE_POSITION = { x=-55, y=4, z=-17 } +PLAY_ZONE_ROTATION = { x=0, y=270, z=0 } +PLAY_ZONE_SCALE = { x=30, y=5, z=15 } + +RESOURCE_COUNTER_GUID = "816d84" + +-- the position of the global discard pile +-- TODO: delegate to global for any auto discard actions +DISCARD_POSITION = {-3.85, 3, 10.38} + +function log(message) + if DEBUG then + print(message) + end +end + +-- builds a function that discards things in searchPostion to discardPostition +function makeDiscardHandlerFor(searchPosition, discardPosition) + return function (_) + local discardItemList = findObjectsAtPosition(searchPosition) + for _, obj in ipairs(discardItemList) do + obj.setPositionSmooth(discardPosition, false, true) + obj.setRotation({0, -90, 0}) + end + end +end + +-- build a discard button at position to discard from searchPosition to discardPosition +-- number must be unique +function makeDiscardButton(position, searchPosition, discardPosition, number) + local handler = makeDiscardHandlerFor(searchPosition, discardPosition) + local handlerName = 'handler' .. number + self.setVar(handlerName, handler) + self.createButton({ + label = "Discard", + click_function= handlerName, + function_owner= self, + position = position, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180, + }) +end + +function onload(save_state) + self.interactable = DEBUG + DATA_HELPER = getObjectFromGUID('708279') + PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') + PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') + + -- positions of encounter card slots + local encounterSlots = { + {1, 0, -0.7}, + {0.55, 0, -0.7}, + {0.1, 0, -0.7}, + {-0.35, 0, -0.7}, + {-0.8, 0, -0.7} + } + + local i = 1 + while i <= 5 do + makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) + i = i + 1 + end + + self.createButton({ + label = " ", + click_function = "drawEncountercard", + function_owner = self, + position = {-1.45,0,-0.7}, + rotation = {0,-15,0}, + width = 170, + height = 255, + font_size = 50 + }) + + self.createButton({ + label=" ", + click_function = "drawChaostokenButton", + function_owner = self, + position = {1.48,0.0,-0.74}, + rotation = {0,-45,0}, + width = 125, + height = 125, + font_size = 50 + }) + + self.createButton({ + label="Upkeep", + click_function = "doUpkeep", + function_owner = self, + position = {1.48,0.1,-0.4}, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180 + }) + + local state = JSON.decode(save_state) + if state ~= nil and state.zoneID ~= nil then + zoneID = state.zoneID + Wait.time(checkDeckZoneExists, 30) + else + spawnDeckZone() + end + + COLLISION_ENABLED = true +end + +function onSave() + return JSON.encode({ zoneID=zoneID }) +end + +function doUpkeep(obj, color, alt_click) + -- right-click binds to new player color + if alt_click then + PLAYER_COLOR = color + printToColor("Upkeep button bound to " .. color, color) + return + end + + -- unexhaust cards in play zone + local objs = Physics.cast({ + origin = PLAY_ZONE_POSITION, + direction = { x=0, y=1, z=0 }, + type = 3, + size = PLAY_ZONE_SCALE, + orientation = PLAY_ZONE_ROTATION + }) + + local y = PLAY_ZONE_ROTATION.y + + local investigator = nil + for i,v in ipairs(objs) do + local obj = v.hit_object + local props = obj.getCustomObject() + if obj.tag == "Card" and not obj.is_face_down then + if props ~= nil and props.unique_back then + local name = obj.getName() + if string.match(name, "Jenny Barnes") ~= nil then + investigator = "Jenny Barnes" + elseif name == "Patrice Hathaway" then + investigator = name + end + else + local r = obj.getRotation() + if (r.y - y > 10) or (y - r.y > 10) then + obj.setRotationSmooth(PLAY_ZONE_ROTATION) + end + end + end + end + + -- gain resource + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + if investigator == "Jenny Barnes" then + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) + end + + -- draw card (shuffle discard if necessary) + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + drawDeck = nil + discardPile = nil + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Deck" or object.tag == "Card" then + if object.is_face_down then + drawDeck = object + else + discardPile = object + end + end + end + + if investigator == "Patrice Hathaway" then + patriceDraw() + return + end + + if drawDeck == nil then + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(1), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) + else + drawCards(1) + end +end + +function drawCards(numCards) + if drawDeck == nil then return end + drawDeck.deal(numCards, PLAYER_COLOR) +end + +function shuffleDiscardIntoDeck() + discardPile.flip() + discardPile.shuffle() + discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) + drawDeck = discardPile + discardPile = nil +end + +function patriceDraw() + local handSize = #Player[PLAYER_COLOR].getHandObjects() + if handSize >= 5 then return end + local cardsToDraw = 5 - handSize + local deckSize + printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) + if drawDeck == nil then + deckSize = 0 + elseif drawDeck.tag == "Deck" then + deckSize = #drawDeck.getObjects() + else + deckSize = 1 + end + + if deckSize >= cardsToDraw then + drawCards(cardsToDraw) + return + end + + drawCards(deckSize) + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(cardsToDraw - deckSize), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) +end + +function checkDeckZoneExists() + if getObjectFromGUID(zoneID) ~= nil then return end + spawnDeckZone() +end + +function spawnDeckZone() + local pos = self.positionToWorld(DECK_POSITION) + local zoneProps = { + position = pos, + scale = DECK_ZONE_SCALE, + type = 'ScriptingTrigger', + callback = 'zoneCallback', + callback_owner = self, + rotation = self.getRotation() + } + spawnObject(zoneProps) +end + +function zoneCallback(zone) + zoneID = zone.getGUID() +end + +function findObjectsAtPosition(localPos) + local globalPos = self.positionToWorld(localPos) + local objList = Physics.cast({ + origin=globalPos, --Where the cast takes place + direction={0,1,0}, --Which direction it moves (up is shown) + type=2, --Type. 2 is "sphere" + size={2,2,2}, --How large that sphere is + max_distance=1, --How far it moves. Just a little bit + debug=false --If it displays the sphere when casting. + }) + local decksAndCards = {} + for _, obj in ipairs(objList) do + if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then + table.insert(decksAndCards, obj.hit_object) + end + end + return decksAndCards +end + +function spawnTokenOn(object, offsets, tokenType) + local tokenPosition = object.positionToWorld(offsets) + spawnToken(tokenPosition, tokenType) +end + +-- spawn a group of tokens of the given type on the object +function spawnTokenGroup(object, tokenType, tokenCount) + local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] + if offsets == nil then + error("couldn't find offsets for " .. tokenCount .. ' tokens') + end + local i = 0 + while i < tokenCount do + local offset = offsets[i + 1] + spawnTokenOn(object, offset, tokenType) + i = i + 1 + end +end + +function buildPlayerCardKey(object) + return object.getName() .. ':' .. object.getDescription() +end + +function getPlayerCardData(object) + return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] +end + +function shouldSpawnTokens(object) + -- we assume we shouldn't spawn tokens if in doubt, this should + -- only ever happen on load and in that case prevents respawns + local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) + local canSpawn = getPlayerCardData(object) + return not spawned and canSpawn +end + +function markSpawned(object) + local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) + if not saved then + error('attempt to mark player card spawned before data loaded') + end +end + +function spawnTokensFor(object) + local data = getPlayerCardData(object) + if data == nil then + error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') + end + log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) + spawnTokenGroup(object, data['tokenType'], data['tokenCount']) + markSpawned(object) +end + +function resetSpawnState() + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Card" then + local guid = object.getGUID() + if guid ~= nil then unmarkSpawned(guid, true) end + elseif object.tag == "Deck" then + local cards = object.getObjects() + if (cards ~= nil) then + for i,v in ipairs(cards) do + if v.guid ~= nil then unmarkSpawned(v.guid) end + end + end + end + end +end + +function unmarkSpawned(guid, force) + if not force and getObjectFromGUID(guid) ~= nil then return end + DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) +end + +function onCollisionEnter(collision_info) + if not COLLISION_ENABLED then + return + end + + local object = collision_info.collision_object + Wait.time(resetSpawnState, 1) + -- anything to the left of this is legal to spawn + local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) + local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) + if boundaryLocalToCard.x > 0 then + log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) + return + end + if not object.is_face_down and shouldSpawnTokens(object) then + spawnTokensFor(object) + end +end + +-- functions delegated to Global +function drawChaostokenButton(object, player, isRightClick) + -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) + Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) +end + +function drawEncountercard(object, player, isRightClick) +local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) +Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) +end + +function spawnToken(position, tokenType) + Global.call('spawnToken', {position, tokenType}) end \ No newline at end of file diff --git a/unpacked/Custom_Tile Playermat 3 Green 383d8b.ttslua b/unpacked/Custom_Tile Playermat 3 Green 383d8b.ttslua index 0f5f45f8a..77cdf233e 100644 --- a/unpacked/Custom_Tile Playermat 3 Green 383d8b.ttslua +++ b/unpacked/Custom_Tile Playermat 3 Green 383d8b.ttslua @@ -1,405 +1,405 @@ --- set true to enable debug logging -DEBUG = false --- we use this to turn off collision handling (for clue spawning) --- until after load is complete (probably a better way to do this) -COLLISION_ENABLED = false --- position offsets, adjust these to reposition things relative to mat [x,y,z] -DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} -DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} -DISCARD_BUTTON_OFFSETS = { - {-0.98, 0.2, -0.945}, - {-0.525, 0.2, -0.945}, - {-0.07, 0.2, -0.945}, - {0.39, 0.2, -0.945}, - {0.84, 0.2, -0.945}, -} --- draw deck and discard zone -DECK_POSITION = { x=-1.4, y=0, z=0.3 } -DECK_ZONE_SCALE = { x=3, y=5, z=8 } -DRAW_DECK_POSITION = { x=-37, y=2.5, z=26.5 } - --- play zone -PLAYER_COLOR = "Green" -PLAY_ZONE_POSITION = { x=-25, y=4, z=27 } -PLAY_ZONE_ROTATION = { x=0, y=0, z=0 } -PLAY_ZONE_SCALE = { x=30, y=5, z=15 } - -RESOURCE_COUNTER_GUID = "cd15ac" - --- the position of the global discard pile --- TODO: delegate to global for any auto discard actions -DISCARD_POSITION = {-3.85, 3, 10.38} - -function log(message) - if DEBUG then - print(message) - end -end - --- builds a function that discards things in searchPostion to discardPostition -function makeDiscardHandlerFor(searchPosition, discardPosition) - return function (_) - local discardItemList = findObjectsAtPosition(searchPosition) - for _, obj in ipairs(discardItemList) do - obj.setPositionSmooth(discardPosition, false, true) - obj.setRotation({0, -90, 0}) - end - end -end - --- build a discard button at position to discard from searchPosition to discardPosition --- number must be unique -function makeDiscardButton(position, searchPosition, discardPosition, number) - local handler = makeDiscardHandlerFor(searchPosition, discardPosition) - local handlerName = 'handler' .. number - self.setVar(handlerName, handler) - self.createButton({ - label = "Discard", - click_function= handlerName, - function_owner= self, - position = position, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180, - }) -end - -function onload(save_state) - self.interactable = DEBUG - DATA_HELPER = getObjectFromGUID('708279') - PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') - PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') - - -- positions of encounter card slots - local encounterSlots = { - {1, 0, -0.7}, - {0.55, 0, -0.7}, - {0.1, 0, -0.7}, - {-0.35, 0, -0.7}, - {-0.8, 0, -0.7} - } - - local i = 1 - while i <= 5 do - makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) - i = i + 1 - end - - self.createButton({ - label = " ", - click_function = "drawEncountercard", - function_owner = self, - position = {-1.45,0,-0.7}, - rotation = {0,-15,0}, - width = 170, - height = 255, - font_size = 50 - }) - - self.createButton({ - label=" ", - click_function = "drawChaostokenButton", - function_owner = self, - position = {1.48,0.0,-0.74}, - rotation = {0,-45,0}, - width = 125, - height = 125, - font_size = 50 - }) - - self.createButton({ - label="Upkeep", - click_function = "doUpkeep", - function_owner = self, - position = {1.48,0.1,-0.4}, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180 - }) - - local state = JSON.decode(save_state) - if state ~= nil and state.zoneID ~= nil then - zoneID = state.zoneID - Wait.time(checkDeckZoneExists, 30) - else - spawnDeckZone() - end - - COLLISION_ENABLED = true -end - -function onSave() - return JSON.encode({ zoneID=zoneID }) -end - -function doUpkeep(obj, color, alt_click) - -- right-click binds to new player color - if alt_click then - PLAYER_COLOR = color - printToColor("Upkeep button bound to " .. color, color) - return - end - - -- unexhaust cards in play zone - local objs = Physics.cast({ - origin = PLAY_ZONE_POSITION, - direction = { x=0, y=1, z=0 }, - type = 3, - size = PLAY_ZONE_SCALE, - orientation = PLAY_ZONE_ROTATION - }) - - local y = PLAY_ZONE_ROTATION.y - - local investigator = nil - for i,v in ipairs(objs) do - local obj = v.hit_object - local props = obj.getCustomObject() - if obj.tag == "Card" and not obj.is_face_down then - if props ~= nil and props.unique_back then - local name = obj.getName() - if string.match(name, "Jenny Barnes") ~= nil then - investigator = "Jenny Barnes" - elseif name == "Patrice Hathaway" then - investigator = name - end - else - local r = obj.getRotation() - if (r.y - y > 10) or (y - r.y > 10) then - obj.setRotationSmooth(PLAY_ZONE_ROTATION) - end - end - end - end - - -- gain resource - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - if investigator == "Jenny Barnes" then - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) - end - - -- draw card (shuffle discard if necessary) - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - drawDeck = nil - discardPile = nil - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Deck" or object.tag == "Card" then - if object.is_face_down then - drawDeck = object - else - discardPile = object - end - end - end - - if investigator == "Patrice Hathaway" then - patriceDraw() - return - end - - if drawDeck == nil then - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(1), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) - else - drawCards(1) - end -end - -function drawCards(numCards) - if drawDeck == nil then return end - drawDeck.deal(numCards, PLAYER_COLOR) -end - -function shuffleDiscardIntoDeck() - discardPile.flip() - discardPile.shuffle() - discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) - drawDeck = discardPile - discardPile = nil -end - -function patriceDraw() - local handSize = #Player[PLAYER_COLOR].getHandObjects() - if handSize >= 5 then return end - local cardsToDraw = 5 - handSize - local deckSize - printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) - if drawDeck == nil then - deckSize = 0 - elseif drawDeck.tag == "Deck" then - deckSize = #drawDeck.getObjects() - else - deckSize = 1 - end - - if deckSize >= cardsToDraw then - drawCards(cardsToDraw) - return - end - - drawCards(deckSize) - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(cardsToDraw - deckSize), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) -end - -function checkDeckZoneExists() - if getObjectFromGUID(zoneID) ~= nil then return end - spawnDeckZone() -end - -function spawnDeckZone() - local pos = self.positionToWorld(DECK_POSITION) - local zoneProps = { - position = pos, - scale = DECK_ZONE_SCALE, - type = 'ScriptingTrigger', - callback = 'zoneCallback', - callback_owner = self, - rotation = self.getRotation() - } - spawnObject(zoneProps) -end - -function zoneCallback(zone) - zoneID = zone.getGUID() -end - -function findObjectsAtPosition(localPos) - local globalPos = self.positionToWorld(localPos) - local objList = Physics.cast({ - origin=globalPos, --Where the cast takes place - direction={0,1,0}, --Which direction it moves (up is shown) - type=2, --Type. 2 is "sphere" - size={2,2,2}, --How large that sphere is - max_distance=1, --How far it moves. Just a little bit - debug=false --If it displays the sphere when casting. - }) - local decksAndCards = {} - for _, obj in ipairs(objList) do - if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then - table.insert(decksAndCards, obj.hit_object) - end - end - return decksAndCards -end - -function spawnTokenOn(object, offsets, tokenType) - local tokenPosition = object.positionToWorld(offsets) - spawnToken(tokenPosition, tokenType) -end - --- spawn a group of tokens of the given type on the object -function spawnTokenGroup(object, tokenType, tokenCount) - local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] - if offsets == nil then - error("couldn't find offsets for " .. tokenCount .. ' tokens') - end - local i = 0 - while i < tokenCount do - local offset = offsets[i + 1] - spawnTokenOn(object, offset, tokenType) - i = i + 1 - end -end - -function buildPlayerCardKey(object) - return object.getName() .. ':' .. object.getDescription() -end - -function getPlayerCardData(object) - return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] -end - -function shouldSpawnTokens(object) - -- we assume we shouldn't spawn tokens if in doubt, this should - -- only ever happen on load and in that case prevents respawns - local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) - local canSpawn = getPlayerCardData(object) - return not spawned and canSpawn -end - -function markSpawned(object) - local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) - if not saved then - error('attempt to mark player card spawned before data loaded') - end -end - -function spawnTokensFor(object) - local data = getPlayerCardData(object) - if data == nil then - error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') - end - log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) - spawnTokenGroup(object, data['tokenType'], data['tokenCount']) - markSpawned(object) -end - -function resetSpawnState() - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Card" then - local guid = object.getGUID() - if guid ~= nil then unmarkSpawned(guid, true) end - elseif object.tag == "Deck" then - local cards = object.getObjects() - if (cards ~= nil) then - for i,v in ipairs(cards) do - if v.guid ~= nil then unmarkSpawned(v.guid) end - end - end - end - end -end - -function unmarkSpawned(guid, force) - if not force and getObjectFromGUID(guid) ~= nil then return end - DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) -end - -function onCollisionEnter(collision_info) - if not COLLISION_ENABLED then - return - end - - local object = collision_info.collision_object - Wait.time(resetSpawnState, 1) - -- anything to the left of this is legal to spawn - local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) - local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) - if boundaryLocalToCard.x > 0 then - log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) - return - end - if not object.is_face_down and shouldSpawnTokens(object) then - spawnTokensFor(object) - end -end - --- functions delegated to Global -function drawChaostokenButton(object, player, isRightClick) - -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) - Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) -end - -function drawEncountercard(object, player, isRightClick) -local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) -Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) -end - -function spawnToken(position, tokenType) - Global.call('spawnToken', {position, tokenType}) +-- set true to enable debug logging +DEBUG = false +-- we use this to turn off collision handling (for clue spawning) +-- until after load is complete (probably a better way to do this) +COLLISION_ENABLED = false +-- position offsets, adjust these to reposition things relative to mat [x,y,z] +DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} +DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} +DISCARD_BUTTON_OFFSETS = { + {-0.98, 0.2, -0.945}, + {-0.525, 0.2, -0.945}, + {-0.07, 0.2, -0.945}, + {0.39, 0.2, -0.945}, + {0.84, 0.2, -0.945}, +} +-- draw deck and discard zone +DECK_POSITION = { x=-1.4, y=0, z=0.3 } +DECK_ZONE_SCALE = { x=3, y=5, z=8 } +DRAW_DECK_POSITION = { x=-37, y=2.5, z=26.5 } + +-- play zone +PLAYER_COLOR = "Green" +PLAY_ZONE_POSITION = { x=-25, y=4, z=27 } +PLAY_ZONE_ROTATION = { x=0, y=0, z=0 } +PLAY_ZONE_SCALE = { x=30, y=5, z=15 } + +RESOURCE_COUNTER_GUID = "cd15ac" + +-- the position of the global discard pile +-- TODO: delegate to global for any auto discard actions +DISCARD_POSITION = {-3.85, 3, 10.38} + +function log(message) + if DEBUG then + print(message) + end +end + +-- builds a function that discards things in searchPostion to discardPostition +function makeDiscardHandlerFor(searchPosition, discardPosition) + return function (_) + local discardItemList = findObjectsAtPosition(searchPosition) + for _, obj in ipairs(discardItemList) do + obj.setPositionSmooth(discardPosition, false, true) + obj.setRotation({0, -90, 0}) + end + end +end + +-- build a discard button at position to discard from searchPosition to discardPosition +-- number must be unique +function makeDiscardButton(position, searchPosition, discardPosition, number) + local handler = makeDiscardHandlerFor(searchPosition, discardPosition) + local handlerName = 'handler' .. number + self.setVar(handlerName, handler) + self.createButton({ + label = "Discard", + click_function= handlerName, + function_owner= self, + position = position, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180, + }) +end + +function onload(save_state) + self.interactable = DEBUG + DATA_HELPER = getObjectFromGUID('708279') + PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') + PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') + + -- positions of encounter card slots + local encounterSlots = { + {1, 0, -0.7}, + {0.55, 0, -0.7}, + {0.1, 0, -0.7}, + {-0.35, 0, -0.7}, + {-0.8, 0, -0.7} + } + + local i = 1 + while i <= 5 do + makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) + i = i + 1 + end + + self.createButton({ + label = " ", + click_function = "drawEncountercard", + function_owner = self, + position = {-1.45,0,-0.7}, + rotation = {0,-15,0}, + width = 170, + height = 255, + font_size = 50 + }) + + self.createButton({ + label=" ", + click_function = "drawChaostokenButton", + function_owner = self, + position = {1.48,0.0,-0.74}, + rotation = {0,-45,0}, + width = 125, + height = 125, + font_size = 50 + }) + + self.createButton({ + label="Upkeep", + click_function = "doUpkeep", + function_owner = self, + position = {1.48,0.1,-0.4}, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180 + }) + + local state = JSON.decode(save_state) + if state ~= nil and state.zoneID ~= nil then + zoneID = state.zoneID + Wait.time(checkDeckZoneExists, 30) + else + spawnDeckZone() + end + + COLLISION_ENABLED = true +end + +function onSave() + return JSON.encode({ zoneID=zoneID }) +end + +function doUpkeep(obj, color, alt_click) + -- right-click binds to new player color + if alt_click then + PLAYER_COLOR = color + printToColor("Upkeep button bound to " .. color, color) + return + end + + -- unexhaust cards in play zone + local objs = Physics.cast({ + origin = PLAY_ZONE_POSITION, + direction = { x=0, y=1, z=0 }, + type = 3, + size = PLAY_ZONE_SCALE, + orientation = PLAY_ZONE_ROTATION + }) + + local y = PLAY_ZONE_ROTATION.y + + local investigator = nil + for i,v in ipairs(objs) do + local obj = v.hit_object + local props = obj.getCustomObject() + if obj.tag == "Card" and not obj.is_face_down then + if props ~= nil and props.unique_back then + local name = obj.getName() + if string.match(name, "Jenny Barnes") ~= nil then + investigator = "Jenny Barnes" + elseif name == "Patrice Hathaway" then + investigator = name + end + else + local r = obj.getRotation() + if (r.y - y > 10) or (y - r.y > 10) then + obj.setRotationSmooth(PLAY_ZONE_ROTATION) + end + end + end + end + + -- gain resource + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + if investigator == "Jenny Barnes" then + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) + end + + -- draw card (shuffle discard if necessary) + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + drawDeck = nil + discardPile = nil + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Deck" or object.tag == "Card" then + if object.is_face_down then + drawDeck = object + else + discardPile = object + end + end + end + + if investigator == "Patrice Hathaway" then + patriceDraw() + return + end + + if drawDeck == nil then + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(1), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) + else + drawCards(1) + end +end + +function drawCards(numCards) + if drawDeck == nil then return end + drawDeck.deal(numCards, PLAYER_COLOR) +end + +function shuffleDiscardIntoDeck() + discardPile.flip() + discardPile.shuffle() + discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) + drawDeck = discardPile + discardPile = nil +end + +function patriceDraw() + local handSize = #Player[PLAYER_COLOR].getHandObjects() + if handSize >= 5 then return end + local cardsToDraw = 5 - handSize + local deckSize + printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) + if drawDeck == nil then + deckSize = 0 + elseif drawDeck.tag == "Deck" then + deckSize = #drawDeck.getObjects() + else + deckSize = 1 + end + + if deckSize >= cardsToDraw then + drawCards(cardsToDraw) + return + end + + drawCards(deckSize) + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(cardsToDraw - deckSize), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) +end + +function checkDeckZoneExists() + if getObjectFromGUID(zoneID) ~= nil then return end + spawnDeckZone() +end + +function spawnDeckZone() + local pos = self.positionToWorld(DECK_POSITION) + local zoneProps = { + position = pos, + scale = DECK_ZONE_SCALE, + type = 'ScriptingTrigger', + callback = 'zoneCallback', + callback_owner = self, + rotation = self.getRotation() + } + spawnObject(zoneProps) +end + +function zoneCallback(zone) + zoneID = zone.getGUID() +end + +function findObjectsAtPosition(localPos) + local globalPos = self.positionToWorld(localPos) + local objList = Physics.cast({ + origin=globalPos, --Where the cast takes place + direction={0,1,0}, --Which direction it moves (up is shown) + type=2, --Type. 2 is "sphere" + size={2,2,2}, --How large that sphere is + max_distance=1, --How far it moves. Just a little bit + debug=false --If it displays the sphere when casting. + }) + local decksAndCards = {} + for _, obj in ipairs(objList) do + if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then + table.insert(decksAndCards, obj.hit_object) + end + end + return decksAndCards +end + +function spawnTokenOn(object, offsets, tokenType) + local tokenPosition = object.positionToWorld(offsets) + spawnToken(tokenPosition, tokenType) +end + +-- spawn a group of tokens of the given type on the object +function spawnTokenGroup(object, tokenType, tokenCount) + local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] + if offsets == nil then + error("couldn't find offsets for " .. tokenCount .. ' tokens') + end + local i = 0 + while i < tokenCount do + local offset = offsets[i + 1] + spawnTokenOn(object, offset, tokenType) + i = i + 1 + end +end + +function buildPlayerCardKey(object) + return object.getName() .. ':' .. object.getDescription() +end + +function getPlayerCardData(object) + return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] +end + +function shouldSpawnTokens(object) + -- we assume we shouldn't spawn tokens if in doubt, this should + -- only ever happen on load and in that case prevents respawns + local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) + local canSpawn = getPlayerCardData(object) + return not spawned and canSpawn +end + +function markSpawned(object) + local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) + if not saved then + error('attempt to mark player card spawned before data loaded') + end +end + +function spawnTokensFor(object) + local data = getPlayerCardData(object) + if data == nil then + error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') + end + log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) + spawnTokenGroup(object, data['tokenType'], data['tokenCount']) + markSpawned(object) +end + +function resetSpawnState() + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Card" then + local guid = object.getGUID() + if guid ~= nil then unmarkSpawned(guid, true) end + elseif object.tag == "Deck" then + local cards = object.getObjects() + if (cards ~= nil) then + for i,v in ipairs(cards) do + if v.guid ~= nil then unmarkSpawned(v.guid) end + end + end + end + end +end + +function unmarkSpawned(guid, force) + if not force and getObjectFromGUID(guid) ~= nil then return end + DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) +end + +function onCollisionEnter(collision_info) + if not COLLISION_ENABLED then + return + end + + local object = collision_info.collision_object + Wait.time(resetSpawnState, 1) + -- anything to the left of this is legal to spawn + local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) + local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) + if boundaryLocalToCard.x > 0 then + log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) + return + end + if not object.is_face_down and shouldSpawnTokens(object) then + spawnTokensFor(object) + end +end + +-- functions delegated to Global +function drawChaostokenButton(object, player, isRightClick) + -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) + Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) +end + +function drawEncountercard(object, player, isRightClick) +local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) +Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) +end + +function spawnToken(position, tokenType) + Global.call('spawnToken', {position, tokenType}) end \ No newline at end of file diff --git a/unpacked/Custom_Tile Playermat 4 Red 0840d5.ttslua b/unpacked/Custom_Tile Playermat 4 Red 0840d5.ttslua index 3bb71d8cf..9351f882d 100644 --- a/unpacked/Custom_Tile Playermat 4 Red 0840d5.ttslua +++ b/unpacked/Custom_Tile Playermat 4 Red 0840d5.ttslua @@ -1,405 +1,405 @@ --- set true to enable debug logging -DEBUG = false --- we use this to turn off collision handling (for clue spawning) --- until after load is complete (probably a better way to do this) -COLLISION_ENABLED = false --- position offsets, adjust these to reposition things relative to mat [x,y,z] -DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} -DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} -DISCARD_BUTTON_OFFSETS = { - {-0.98, 0.2, -0.945}, - {-0.525, 0.2, -0.945}, - {-0.07, 0.2, -0.945}, - {0.39, 0.2, -0.945}, - {0.84, 0.2, -0.945}, -} --- draw deck and discard zone -DECK_POSITION = { x=-1.4, y=0, z=0.3 } -DECK_ZONE_SCALE = { x=3, y=5, z=8 } -DRAW_DECK_POSITION = { x=-18.9, y=2.5, z=-26.7 } - --- play zone -PLAYER_COLOR = "Red" -PLAY_ZONE_POSITION = { x=-25, y=4, z=-27 } -PLAY_ZONE_ROTATION = { x=0, y=180, z=0 } -PLAY_ZONE_SCALE = { x=30, y=5, z=15 } - -RESOURCE_COUNTER_GUID = "a4b60d" - --- the position of the global discard pile --- TODO: delegate to global for any auto discard actions -DISCARD_POSITION = {-3.85, 3, 10.38} - -function log(message) - if DEBUG then - print(message) - end -end - --- builds a function that discards things in searchPostion to discardPostition -function makeDiscardHandlerFor(searchPosition, discardPosition) - return function (_) - local discardItemList = findObjectsAtPosition(searchPosition) - for _, obj in ipairs(discardItemList) do - obj.setPositionSmooth(discardPosition, false, true) - obj.setRotation({0, -90, 0}) - end - end -end - --- build a discard button at position to discard from searchPosition to discardPosition --- number must be unique -function makeDiscardButton(position, searchPosition, discardPosition, number) - local handler = makeDiscardHandlerFor(searchPosition, discardPosition) - local handlerName = 'handler' .. number - self.setVar(handlerName, handler) - self.createButton({ - label = "Discard", - click_function= handlerName, - function_owner= self, - position = position, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180, - }) -end - -function onload(save_state) - self.interactable = DEBUG - DATA_HELPER = getObjectFromGUID('708279') - PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') - PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') - - -- positions of encounter card slots - local encounterSlots = { - {1, 0, -0.7}, - {0.55, 0, -0.7}, - {0.1, 0, -0.7}, - {-0.35, 0, -0.7}, - {-0.8, 0, -0.7} - } - - local i = 1 - while i <= 5 do - makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) - i = i + 1 - end - - self.createButton({ - label = " ", - click_function = "drawEncountercard", - function_owner = self, - position = {-1.45,0,-0.7}, - rotation = {0,-15,0}, - width = 170, - height = 255, - font_size = 50 - }) - - self.createButton({ - label=" ", - click_function = "drawChaostokenButton", - function_owner = self, - position = {1.48,0.0,-0.74}, - rotation = {0,-45,0}, - width = 125, - height = 125, - font_size = 50 - }) - - self.createButton({ - label="Upkeep", - click_function = "doUpkeep", - function_owner = self, - position = {1.48,0.1,-0.4}, - scale = {0.12, 0.12, 0.12}, - width = 800, - height = 280, - font_size = 180 - }) - - local state = JSON.decode(save_state) - if state ~= nil and state.zoneID ~= nil then - zoneID = state.zoneID - Wait.time(checkDeckZoneExists, 30) - else - spawnDeckZone() - end - - COLLISION_ENABLED = true -end - -function onSave() - return JSON.encode({ zoneID=zoneID }) -end - -function doUpkeep(obj, color, alt_click) - -- right-click binds to new player color - if alt_click then - PLAYER_COLOR = color - printToColor("Upkeep button bound to " .. color, color) - return - end - - -- unexhaust cards in play zone - local objs = Physics.cast({ - origin = PLAY_ZONE_POSITION, - direction = { x=0, y=1, z=0 }, - type = 3, - size = PLAY_ZONE_SCALE, - orientation = PLAY_ZONE_ROTATION - }) - - local y = PLAY_ZONE_ROTATION.y - - local investigator = nil - for i,v in ipairs(objs) do - local obj = v.hit_object - local props = obj.getCustomObject() - if obj.tag == "Card" and not obj.is_face_down then - if props ~= nil and props.unique_back then - local name = obj.getName() - if string.match(name, "Jenny Barnes") ~= nil then - investigator = "Jenny Barnes" - elseif name == "Patrice Hathaway" then - investigator = name - end - else - local r = obj.getRotation() - if (r.y - y > 10) or (y - r.y > 10) then - obj.setRotationSmooth(PLAY_ZONE_ROTATION) - end - end - end - end - - -- gain resource - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - if investigator == "Jenny Barnes" then - getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") - printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) - end - - -- draw card (shuffle discard if necessary) - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - drawDeck = nil - discardPile = nil - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Deck" or object.tag == "Card" then - if object.is_face_down then - drawDeck = object - else - discardPile = object - end - end - end - - if investigator == "Patrice Hathaway" then - patriceDraw() - return - end - - if drawDeck == nil then - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(1), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) - else - drawCards(1) - end -end - -function drawCards(numCards) - if drawDeck == nil then return end - drawDeck.deal(numCards, PLAYER_COLOR) -end - -function shuffleDiscardIntoDeck() - discardPile.flip() - discardPile.shuffle() - discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) - drawDeck = discardPile - discardPile = nil -end - -function patriceDraw() - local handSize = #Player[PLAYER_COLOR].getHandObjects() - if handSize >= 5 then return end - local cardsToDraw = 5 - handSize - local deckSize - printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) - if drawDeck == nil then - deckSize = 0 - elseif drawDeck.tag == "Deck" then - deckSize = #drawDeck.getObjects() - else - deckSize = 1 - end - - if deckSize >= cardsToDraw then - drawCards(cardsToDraw) - return - end - - drawCards(deckSize) - if discardPile ~= nil then - shuffleDiscardIntoDeck() - Wait.time(|| drawCards(cardsToDraw - deckSize), 1) - end - printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) -end - -function checkDeckZoneExists() - if getObjectFromGUID(zoneID) ~= nil then return end - spawnDeckZone() -end - -function spawnDeckZone() - local pos = self.positionToWorld(DECK_POSITION) - local zoneProps = { - position = pos, - scale = DECK_ZONE_SCALE, - type = 'ScriptingTrigger', - callback = 'zoneCallback', - callback_owner = self, - rotation = self.getRotation() - } - spawnObject(zoneProps) -end - -function zoneCallback(zone) - zoneID = zone.getGUID() -end - -function findObjectsAtPosition(localPos) - local globalPos = self.positionToWorld(localPos) - local objList = Physics.cast({ - origin=globalPos, --Where the cast takes place - direction={0,1,0}, --Which direction it moves (up is shown) - type=2, --Type. 2 is "sphere" - size={2,2,2}, --How large that sphere is - max_distance=1, --How far it moves. Just a little bit - debug=false --If it displays the sphere when casting. - }) - local decksAndCards = {} - for _, obj in ipairs(objList) do - if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then - table.insert(decksAndCards, obj.hit_object) - end - end - return decksAndCards -end - -function spawnTokenOn(object, offsets, tokenType) - local tokenPosition = object.positionToWorld(offsets) - spawnToken(tokenPosition, tokenType) -end - --- spawn a group of tokens of the given type on the object -function spawnTokenGroup(object, tokenType, tokenCount) - local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] - if offsets == nil then - error("couldn't find offsets for " .. tokenCount .. ' tokens') - end - local i = 0 - while i < tokenCount do - local offset = offsets[i + 1] - spawnTokenOn(object, offset, tokenType) - i = i + 1 - end -end - -function buildPlayerCardKey(object) - return object.getName() .. ':' .. object.getDescription() -end - -function getPlayerCardData(object) - return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] -end - -function shouldSpawnTokens(object) - -- we assume we shouldn't spawn tokens if in doubt, this should - -- only ever happen on load and in that case prevents respawns - local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) - local canSpawn = getPlayerCardData(object) - return not spawned and canSpawn -end - -function markSpawned(object) - local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) - if not saved then - error('attempt to mark player card spawned before data loaded') - end -end - -function spawnTokensFor(object) - local data = getPlayerCardData(object) - if data == nil then - error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') - end - log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) - spawnTokenGroup(object, data['tokenType'], data['tokenCount']) - markSpawned(object) -end - -function resetSpawnState() - local zone = getObjectFromGUID(zoneID) - if zone == nil then return end - - for i,object in ipairs(zone.getObjects()) do - if object.tag == "Card" then - local guid = object.getGUID() - if guid ~= nil then unmarkSpawned(guid, true) end - elseif object.tag == "Deck" then - local cards = object.getObjects() - if (cards ~= nil) then - for i,v in ipairs(cards) do - if v.guid ~= nil then unmarkSpawned(v.guid) end - end - end - end - end -end - -function unmarkSpawned(guid, force) - if not force and getObjectFromGUID(guid) ~= nil then return end - DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) -end - -function onCollisionEnter(collision_info) - if not COLLISION_ENABLED then - return - end - - local object = collision_info.collision_object - Wait.time(resetSpawnState, 1) - -- anything to the left of this is legal to spawn - local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) - local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) - if boundaryLocalToCard.x > 0 then - log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) - return - end - if not object.is_face_down and shouldSpawnTokens(object) then - spawnTokensFor(object) - end -end - --- functions delegated to Global -function drawChaostokenButton(object, player, isRightClick) - -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) - Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) -end - -function drawEncountercard(object, player, isRightClick) -local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) -Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) -end - -function spawnToken(position, tokenType) - Global.call('spawnToken', {position, tokenType}) +-- set true to enable debug logging +DEBUG = false +-- we use this to turn off collision handling (for clue spawning) +-- until after load is complete (probably a better way to do this) +COLLISION_ENABLED = false +-- position offsets, adjust these to reposition things relative to mat [x,y,z] +DRAWN_ENCOUNTER_CARD_OFFSET = {0.98, 0.5, -0.635} +DRAWN_CHAOS_TOKEN_OFFSET = {-1.2, 0.5, -0.45} +DISCARD_BUTTON_OFFSETS = { + {-0.98, 0.2, -0.945}, + {-0.525, 0.2, -0.945}, + {-0.07, 0.2, -0.945}, + {0.39, 0.2, -0.945}, + {0.84, 0.2, -0.945}, +} +-- draw deck and discard zone +DECK_POSITION = { x=-1.4, y=0, z=0.3 } +DECK_ZONE_SCALE = { x=3, y=5, z=8 } +DRAW_DECK_POSITION = { x=-18.9, y=2.5, z=-26.7 } + +-- play zone +PLAYER_COLOR = "Red" +PLAY_ZONE_POSITION = { x=-25, y=4, z=-27 } +PLAY_ZONE_ROTATION = { x=0, y=180, z=0 } +PLAY_ZONE_SCALE = { x=30, y=5, z=15 } + +RESOURCE_COUNTER_GUID = "a4b60d" + +-- the position of the global discard pile +-- TODO: delegate to global for any auto discard actions +DISCARD_POSITION = {-3.85, 3, 10.38} + +function log(message) + if DEBUG then + print(message) + end +end + +-- builds a function that discards things in searchPostion to discardPostition +function makeDiscardHandlerFor(searchPosition, discardPosition) + return function (_) + local discardItemList = findObjectsAtPosition(searchPosition) + for _, obj in ipairs(discardItemList) do + obj.setPositionSmooth(discardPosition, false, true) + obj.setRotation({0, -90, 0}) + end + end +end + +-- build a discard button at position to discard from searchPosition to discardPosition +-- number must be unique +function makeDiscardButton(position, searchPosition, discardPosition, number) + local handler = makeDiscardHandlerFor(searchPosition, discardPosition) + local handlerName = 'handler' .. number + self.setVar(handlerName, handler) + self.createButton({ + label = "Discard", + click_function= handlerName, + function_owner= self, + position = position, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180, + }) +end + +function onload(save_state) + self.interactable = DEBUG + DATA_HELPER = getObjectFromGUID('708279') + PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') + PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') + + -- positions of encounter card slots + local encounterSlots = { + {1, 0, -0.7}, + {0.55, 0, -0.7}, + {0.1, 0, -0.7}, + {-0.35, 0, -0.7}, + {-0.8, 0, -0.7} + } + + local i = 1 + while i <= 5 do + makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], encounterSlots[i], DISCARD_POSITION, i) + i = i + 1 + end + + self.createButton({ + label = " ", + click_function = "drawEncountercard", + function_owner = self, + position = {-1.45,0,-0.7}, + rotation = {0,-15,0}, + width = 170, + height = 255, + font_size = 50 + }) + + self.createButton({ + label=" ", + click_function = "drawChaostokenButton", + function_owner = self, + position = {1.48,0.0,-0.74}, + rotation = {0,-45,0}, + width = 125, + height = 125, + font_size = 50 + }) + + self.createButton({ + label="Upkeep", + click_function = "doUpkeep", + function_owner = self, + position = {1.48,0.1,-0.4}, + scale = {0.12, 0.12, 0.12}, + width = 800, + height = 280, + font_size = 180 + }) + + local state = JSON.decode(save_state) + if state ~= nil and state.zoneID ~= nil then + zoneID = state.zoneID + Wait.time(checkDeckZoneExists, 30) + else + spawnDeckZone() + end + + COLLISION_ENABLED = true +end + +function onSave() + return JSON.encode({ zoneID=zoneID }) +end + +function doUpkeep(obj, color, alt_click) + -- right-click binds to new player color + if alt_click then + PLAYER_COLOR = color + printToColor("Upkeep button bound to " .. color, color) + return + end + + -- unexhaust cards in play zone + local objs = Physics.cast({ + origin = PLAY_ZONE_POSITION, + direction = { x=0, y=1, z=0 }, + type = 3, + size = PLAY_ZONE_SCALE, + orientation = PLAY_ZONE_ROTATION + }) + + local y = PLAY_ZONE_ROTATION.y + + local investigator = nil + for i,v in ipairs(objs) do + local obj = v.hit_object + local props = obj.getCustomObject() + if obj.tag == "Card" and not obj.is_face_down then + if props ~= nil and props.unique_back then + local name = obj.getName() + if string.match(name, "Jenny Barnes") ~= nil then + investigator = "Jenny Barnes" + elseif name == "Patrice Hathaway" then + investigator = name + end + else + local r = obj.getRotation() + if (r.y - y > 10) or (y - r.y > 10) then + obj.setRotationSmooth(PLAY_ZONE_ROTATION) + end + end + end + end + + -- gain resource + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + if investigator == "Jenny Barnes" then + getObjectFromGUID(RESOURCE_COUNTER_GUID).call("add_subtract") + printToColor("Taking 2 resources (Jenny)", PLAYER_COLOR) + end + + -- draw card (shuffle discard if necessary) + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + drawDeck = nil + discardPile = nil + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Deck" or object.tag == "Card" then + if object.is_face_down then + drawDeck = object + else + discardPile = object + end + end + end + + if investigator == "Patrice Hathaway" then + patriceDraw() + return + end + + if drawDeck == nil then + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(1), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) + else + drawCards(1) + end +end + +function drawCards(numCards) + if drawDeck == nil then return end + drawDeck.deal(numCards, PLAYER_COLOR) +end + +function shuffleDiscardIntoDeck() + discardPile.flip() + discardPile.shuffle() + discardPile.setPositionSmooth(DRAW_DECK_POSITION, false, false) + drawDeck = discardPile + discardPile = nil +end + +function patriceDraw() + local handSize = #Player[PLAYER_COLOR].getHandObjects() + if handSize >= 5 then return end + local cardsToDraw = 5 - handSize + local deckSize + printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", PLAYER_COLOR) + if drawDeck == nil then + deckSize = 0 + elseif drawDeck.tag == "Deck" then + deckSize = #drawDeck.getObjects() + else + deckSize = 1 + end + + if deckSize >= cardsToDraw then + drawCards(cardsToDraw) + return + end + + drawCards(deckSize) + if discardPile ~= nil then + shuffleDiscardIntoDeck() + Wait.time(|| drawCards(cardsToDraw - deckSize), 1) + end + printToColor("Take 1 horror (drawing card from empty deck)", PLAYER_COLOR) +end + +function checkDeckZoneExists() + if getObjectFromGUID(zoneID) ~= nil then return end + spawnDeckZone() +end + +function spawnDeckZone() + local pos = self.positionToWorld(DECK_POSITION) + local zoneProps = { + position = pos, + scale = DECK_ZONE_SCALE, + type = 'ScriptingTrigger', + callback = 'zoneCallback', + callback_owner = self, + rotation = self.getRotation() + } + spawnObject(zoneProps) +end + +function zoneCallback(zone) + zoneID = zone.getGUID() +end + +function findObjectsAtPosition(localPos) + local globalPos = self.positionToWorld(localPos) + local objList = Physics.cast({ + origin=globalPos, --Where the cast takes place + direction={0,1,0}, --Which direction it moves (up is shown) + type=2, --Type. 2 is "sphere" + size={2,2,2}, --How large that sphere is + max_distance=1, --How far it moves. Just a little bit + debug=false --If it displays the sphere when casting. + }) + local decksAndCards = {} + for _, obj in ipairs(objList) do + if obj.hit_object.tag == "Deck" or obj.hit_object.tag == "Card" then + table.insert(decksAndCards, obj.hit_object) + end + end + return decksAndCards +end + +function spawnTokenOn(object, offsets, tokenType) + local tokenPosition = object.positionToWorld(offsets) + spawnToken(tokenPosition, tokenType) +end + +-- spawn a group of tokens of the given type on the object +function spawnTokenGroup(object, tokenType, tokenCount) + local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount] + if offsets == nil then + error("couldn't find offsets for " .. tokenCount .. ' tokens') + end + local i = 0 + while i < tokenCount do + local offset = offsets[i + 1] + spawnTokenOn(object, offset, tokenType) + i = i + 1 + end +end + +function buildPlayerCardKey(object) + return object.getName() .. ':' .. object.getDescription() +end + +function getPlayerCardData(object) + return PLAYER_CARDS[buildPlayerCardKey(object)] or PLAYER_CARDS[object.getName()] +end + +function shouldSpawnTokens(object) + -- we assume we shouldn't spawn tokens if in doubt, this should + -- only ever happen on load and in that case prevents respawns + local spawned = DATA_HELPER.call('getSpawnedPlayerCardGuid', {object.getGUID()}) + local canSpawn = getPlayerCardData(object) + return not spawned and canSpawn +end + +function markSpawned(object) + local saved = DATA_HELPER.call('setSpawnedPlayerCardGuid', {object.getGUID(), true}) + if not saved then + error('attempt to mark player card spawned before data loaded') + end +end + +function spawnTokensFor(object) + local data = getPlayerCardData(object) + if data == nil then + error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') + end + log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) + spawnTokenGroup(object, data['tokenType'], data['tokenCount']) + markSpawned(object) +end + +function resetSpawnState() + local zone = getObjectFromGUID(zoneID) + if zone == nil then return end + + for i,object in ipairs(zone.getObjects()) do + if object.tag == "Card" then + local guid = object.getGUID() + if guid ~= nil then unmarkSpawned(guid, true) end + elseif object.tag == "Deck" then + local cards = object.getObjects() + if (cards ~= nil) then + for i,v in ipairs(cards) do + if v.guid ~= nil then unmarkSpawned(v.guid) end + end + end + end + end +end + +function unmarkSpawned(guid, force) + if not force and getObjectFromGUID(guid) ~= nil then return end + DATA_HELPER.call('setSpawnedPlayerCardGuid', {guid, false}) +end + +function onCollisionEnter(collision_info) + if not COLLISION_ENABLED then + return + end + + local object = collision_info.collision_object + Wait.time(resetSpawnState, 1) + -- anything to the left of this is legal to spawn + local discardSpawnBoundary = self.positionToWorld({-1.2, 0, 0}) + local boundaryLocalToCard = object.positionToLocal(discardSpawnBoundary) + if boundaryLocalToCard.x > 0 then + log('not checking for token spawn, boundary relative is ' .. boundaryLocalToCard.x) + return + end + if not object.is_face_down and shouldSpawnTokens(object) then + spawnTokensFor(object) + end +end + +-- functions delegated to Global +function drawChaostokenButton(object, player, isRightClick) + -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) + Global.call("drawChaostoken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick}) +end + +function drawEncountercard(object, player, isRightClick) +local toPosition = self.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) +Global.call("drawEncountercard", {toPosition, self.getRotation(), isRightClick}) +end + +function spawnToken(position, tokenType) + Global.call('spawnToken', {position, tokenType}) end \ No newline at end of file diff --git a/unpacked/Custom_Token b7b45b.ttslua b/unpacked/Custom_Token b7b45b.ttslua index cba82b051..d80e1b252 100644 --- a/unpacked/Custom_Token b7b45b.ttslua +++ b/unpacked/Custom_Token b7b45b.ttslua @@ -1,199 +1,199 @@ - - -function onSave() - saved_data = JSON.encode({tid=tableImageData, cd=checkData}) - --saved_data = "" - return saved_data -end - -function onload(saved_data) - --Loads the tracking for if the game has started yet - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - tableImageData = loaded_data.tid - checkData = loaded_data.cd - else - tableImageData = {} - checkData = {move=false, scale=false} - end - - --Disables interactable status of objects with GUID in list - for _, guid in ipairs(ref_noninteractable) do - local obj = getObjectFromGUID(guid) - if obj then obj.interactable = false end - end - - - - obj_surface = getObjectFromGUID("721ba2") - - - controlActive = false - createOpenCloseButton() -end - - - ---Activation/deactivation of control panel - - - ---Activated by clicking on -function click_toggleControl(_, color) - if permissionCheck(color) then - if not controlActive then - --Activate control panel - controlActive = true - self.clearButtons() - createOpenCloseButton() - createSurfaceInput() - createSurfaceButtons() - - else - --Deactivate control panel - controlActive = false - self.clearButtons() - self.clearInputs() - createOpenCloseButton() - - end - end -end - - - - ---Table surface control - - - ---Changes table surface -function click_applySurface(_, color) - if permissionCheck(color) then - updateSurface() - broadcastToAll("New Playmat Image Applied", {0.2,0.9,0.2}) - end -end - ---Updates surface from the values in the input field -function updateSurface() - local customInfo = obj_surface.getCustomObject() - customInfo.image = self.getInputs()[1].value - obj_surface.setCustomObject(customInfo) - obj_surface = obj_surface.reload() -end - - - ---Information gathering - - - ---Checks if a color is promoted or host -function permissionCheck(color) - if Player[color].host==true or Player[color].promoted==true then - return true - else - return false - end -end - ---Locates a string saved within memory file -function findInImageDataIndex(...) - for _, str in ipairs({...}) do - for i, v in ipairs(tableImageData) do - if v.url == str or v.name == str then - return i - end - end - end - return nil -end - ---Round number (num) to the Nth decimal (dec) -function round(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end - ---Locates a button with a helper function -function findButton(obj, func) - if func==nil then error("No func supplied to findButton") end - for _, v in ipairs(obj.getButtons()) do - if func(v) then - return v - end - end - return nil -end - - - ---Creation of buttons/inputs - - - -function createOpenCloseButton() - local tooltip = "Open Playmat Panel" - if controlActive then - tooltip = "Close Playmat Panel" - end - self.createButton({ - click_function="click_toggleControl", function_owner=self, - position={0,0,0}, rotation={-45,0,0}, height=1500, width=1500, - color={1,1,1,0}, tooltip=tooltip - }) -end - -function createSurfaceInput() - local currentURL = obj_surface.getCustomObject().diffuse - local nickname = "" - if findInImageDataIndex(currentURL) ~= nil then - nickname = tableImageData[findInImageDataIndex(currentURL)].name - end - - self.createInput({ - label="URL", input_function="none", function_owner=self, - alignment=3, position={0,0.15,3}, height=224, width=4000, - font_size=200, tooltip="Enter URL for playmat image", - value=currentURL - }) -end - -function createSurfaceButtons() - --Label - self.createButton({ - label="Playmat Image Swapper", click_function="none", - position={0,0.15,2.2}, height=0, width=0, font_size=300, font_color={1,1,1} - }) - --Functional - self.createButton({ - label="Apply Image\nTo Playmat", click_function="click_applySurface", - function_owner=self, tooltip="Apply URL as playmat image", - position={0,0.15,4}, height=440, width=1400, font_size=200, - }) - -end - - - - - - ---Data tables - - - - -ref_noninteractable = { - "afc863","c8edca","393bf7","12c65e","f938a2","9f95fd","35b95f", - "5af8f2","4ee1f2","bd69bd" -} - -ref_playerColor = { - "White", "Brown", "Red", "Orange", "Yellow", - "Green", "Teal", "Blue", "Purple", "Pink", "Black" -} - ---Dummy function, absorbs unwanted triggers + + +function onSave() + saved_data = JSON.encode({tid=tableImageData, cd=checkData}) + --saved_data = "" + return saved_data +end + +function onload(saved_data) + --Loads the tracking for if the game has started yet + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + tableImageData = loaded_data.tid + checkData = loaded_data.cd + else + tableImageData = {} + checkData = {move=false, scale=false} + end + + --Disables interactable status of objects with GUID in list + for _, guid in ipairs(ref_noninteractable) do + local obj = getObjectFromGUID(guid) + if obj then obj.interactable = false end + end + + + + obj_surface = getObjectFromGUID("721ba2") + + + controlActive = false + createOpenCloseButton() +end + + + +--Activation/deactivation of control panel + + + +--Activated by clicking on +function click_toggleControl(_, color) + if permissionCheck(color) then + if not controlActive then + --Activate control panel + controlActive = true + self.clearButtons() + createOpenCloseButton() + createSurfaceInput() + createSurfaceButtons() + + else + --Deactivate control panel + controlActive = false + self.clearButtons() + self.clearInputs() + createOpenCloseButton() + + end + end +end + + + + +--Table surface control + + + +--Changes table surface +function click_applySurface(_, color) + if permissionCheck(color) then + updateSurface() + broadcastToAll("New Playmat Image Applied", {0.2,0.9,0.2}) + end +end + +--Updates surface from the values in the input field +function updateSurface() + local customInfo = obj_surface.getCustomObject() + customInfo.image = self.getInputs()[1].value + obj_surface.setCustomObject(customInfo) + obj_surface = obj_surface.reload() +end + + + +--Information gathering + + + +--Checks if a color is promoted or host +function permissionCheck(color) + if Player[color].host==true or Player[color].promoted==true then + return true + else + return false + end +end + +--Locates a string saved within memory file +function findInImageDataIndex(...) + for _, str in ipairs({...}) do + for i, v in ipairs(tableImageData) do + if v.url == str or v.name == str then + return i + end + end + end + return nil +end + +--Round number (num) to the Nth decimal (dec) +function round(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end + +--Locates a button with a helper function +function findButton(obj, func) + if func==nil then error("No func supplied to findButton") end + for _, v in ipairs(obj.getButtons()) do + if func(v) then + return v + end + end + return nil +end + + + +--Creation of buttons/inputs + + + +function createOpenCloseButton() + local tooltip = "Open Playmat Panel" + if controlActive then + tooltip = "Close Playmat Panel" + end + self.createButton({ + click_function="click_toggleControl", function_owner=self, + position={0,0,0}, rotation={-45,0,0}, height=1500, width=1500, + color={1,1,1,0}, tooltip=tooltip + }) +end + +function createSurfaceInput() + local currentURL = obj_surface.getCustomObject().diffuse + local nickname = "" + if findInImageDataIndex(currentURL) ~= nil then + nickname = tableImageData[findInImageDataIndex(currentURL)].name + end + + self.createInput({ + label="URL", input_function="none", function_owner=self, + alignment=3, position={0,0.15,3}, height=224, width=4000, + font_size=200, tooltip="Enter URL for playmat image", + value=currentURL + }) +end + +function createSurfaceButtons() + --Label + self.createButton({ + label="Playmat Image Swapper", click_function="none", + position={0,0.15,2.2}, height=0, width=0, font_size=300, font_color={1,1,1} + }) + --Functional + self.createButton({ + label="Apply Image\nTo Playmat", click_function="click_applySurface", + function_owner=self, tooltip="Apply URL as playmat image", + position={0,0.15,4}, height=440, width=1400, font_size=200, + }) + +end + + + + + + +--Data tables + + + + +ref_noninteractable = { + "afc863","c8edca","393bf7","12c65e","f938a2","9f95fd","35b95f", + "5af8f2","4ee1f2","bd69bd" +} + +ref_playerColor = { + "White", "Brown", "Red", "Orange", "Yellow", + "Green", "Teal", "Blue", "Purple", "Pink", "Black" +} + +--Dummy function, absorbs unwanted triggers function none() end \ No newline at end of file diff --git a/unpacked/Custom_Token Agenda Deck 85c4c6.ttslua b/unpacked/Custom_Token Agenda Deck 85c4c6.ttslua index ee5b7a827..7aacde2cb 100644 --- a/unpacked/Custom_Token Agenda Deck 85c4c6.ttslua +++ b/unpacked/Custom_Token Agenda Deck 85c4c6.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {1,1,1,95} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={0,0,0,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {1,1,1,95} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={0,0,0,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Chaos Bag Stat Tracker 766620.ttslua b/unpacked/Custom_Token Chaos Bag Stat Tracker 766620.ttslua index 11d95d262..56ef4b7fe 100644 --- a/unpacked/Custom_Token Chaos Bag Stat Tracker 766620.ttslua +++ b/unpacked/Custom_Token Chaos Bag Stat Tracker 766620.ttslua @@ -1,101 +1,101 @@ -function onload(saved_data) - light_mode = false - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - end - createAll() -end - --- functions delegated to Global -function printStats(object, player, isRightClick) - -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) - if isRightClick then - Global.call("resetStats") - else - Global.call("printStats") - end -end - -function updateSave() - local data_to_save = {light_mode } - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {1,1,1,95} - else - f_color = {0,0,0,100} - end - - self.createButton({ - click_function="printStats", - function_owner=self, - position={0,0.05,0}, - height=600, - width=1000, - alignment = 3, - tooltip = "Left Click to print stats. Right Click to reset them.", - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={0,0,0,0} - }) - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = "Left click to show stats. Right click to reset them." - }) -end - -function keepSample(_obj, _string, value) - reloadAll() -end - -function onDestroy() - Timer.destroy(timerID) +function onload(saved_data) + light_mode = false + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + end + createAll() +end + +-- functions delegated to Global +function printStats(object, player, isRightClick) + -- local toPosition = self.positionToWorld(DRAWN_CHAOS_TOKEN_OFFSET) + if isRightClick then + Global.call("resetStats") + else + Global.call("printStats") + end +end + +function updateSave() + local data_to_save = {light_mode } + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {1,1,1,95} + else + f_color = {0,0,0,100} + end + + self.createButton({ + click_function="printStats", + function_owner=self, + position={0,0.05,0}, + height=600, + width=1000, + alignment = 3, + tooltip = "Left Click to print stats. Right Click to reset them.", + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={0,0,0,0} + }) + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = "Left click to show stats. Right click to reset them." + }) +end + +function keepSample(_obj, _string, value) + reloadAll() +end + +function onDestroy() + Timer.destroy(timerID) end \ No newline at end of file diff --git a/unpacked/Custom_Token Damage 1f5a0a.ttslua b/unpacked/Custom_Token Damage 1f5a0a.ttslua index 3a20df99e..690cc9178 100644 --- a/unpacked/Custom_Token Damage 1f5a0a.ttslua +++ b/unpacked/Custom_Token Damage 1f5a0a.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0.1,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0.1,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Damage 591a45.ttslua b/unpacked/Custom_Token Damage 591a45.ttslua index 3a20df99e..690cc9178 100644 --- a/unpacked/Custom_Token Damage 591a45.ttslua +++ b/unpacked/Custom_Token Damage 591a45.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0.1,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0.1,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Damage e64eec.ttslua b/unpacked/Custom_Token Damage e64eec.ttslua index 3a20df99e..690cc9178 100644 --- a/unpacked/Custom_Token Damage e64eec.ttslua +++ b/unpacked/Custom_Token Damage e64eec.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0.1,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0.1,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Damage eb08d6.ttslua b/unpacked/Custom_Token Damage eb08d6.ttslua index 3a20df99e..690cc9178 100644 --- a/unpacked/Custom_Token Damage eb08d6.ttslua +++ b/unpacked/Custom_Token Damage eb08d6.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0.1,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0.1,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Horror 0257d9.ttslua b/unpacked/Custom_Token Horror 0257d9.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Token Horror 0257d9.ttslua +++ b/unpacked/Custom_Token Horror 0257d9.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Horror 468e88.ttslua b/unpacked/Custom_Token Horror 468e88.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Token Horror 468e88.ttslua +++ b/unpacked/Custom_Token Horror 468e88.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Horror 7b5729.ttslua b/unpacked/Custom_Token Horror 7b5729.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Token Horror 7b5729.ttslua +++ b/unpacked/Custom_Token Horror 7b5729.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Horror beb964.ttslua b/unpacked/Custom_Token Horror beb964.ttslua index 639b2e969..895f01f1f 100644 --- a/unpacked/Custom_Token Horror beb964.ttslua +++ b/unpacked/Custom_Token Horror beb964.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={-0.025,0.05,-0.025}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={-0.025,0.05,-0.025}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Master Clue Counter 4a3aa4.ttslua b/unpacked/Custom_Token Master Clue Counter 4a3aa4.ttslua index 07c0cf077..507874c32 100644 --- a/unpacked/Custom_Token Master Clue Counter 4a3aa4.ttslua +++ b/unpacked/Custom_Token Master Clue Counter 4a3aa4.ttslua @@ -1,158 +1,158 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = false - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - p1ClueCounter = getObjectFromGUID("37be78") - p2ClueCounter = getObjectFromGUID("1769ed") - p3ClueCounter = getObjectFromGUID("032300") - p4ClueCounter = getObjectFromGUID("d86b7c") - - timerID = self.getGUID()..math.random(9999999999999) - Timer.create({ - identifier=timerID, - function_name="totalCounters", function_owner=self, - repetitions=0, delay=1 - }) - createAll() -end - -function loadPlayerCounters() - p1ClueCounter = getObjectFromGUID("37be78") - p2ClueCounter = getObjectFromGUID("1769ed") - p3ClueCounter = getObjectFromGUID("032300") - p4ClueCounter = getObjectFromGUID("d86b7c") -end - - -function totalCounters() - if p1ClueCounter == nil or p2ClueCounter == nil or p3ClueCounter == nil or p4ClueCounter == nil then - loadPlayerCounters() - end - local p1ClueCount = p1ClueCounter.getVar("exposedValue") - local p2ClueCount = p2ClueCounter.getVar("exposedValue") - local p3ClueCount = p3ClueCounter.getVar("exposedValue") - local p4ClueCount = p4ClueCounter.getVar("exposedValue") - val = tonumber(p1ClueCount) + tonumber(p2ClueCount) + tonumber(p3ClueCount) + tonumber(p4ClueCount) - updateVal() - updateSave() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0.5, 0.5, 0.5, 95} - - if light_mode then - f_color = {1,1,1,95} - else - f_color = {0,0,0,100} - end - - self.createButton({ - label=tostring(val), - click_function="removeAllPlayerClues", - function_owner=self, - position={0,0.05,0}, - height=600, - width=1000, - alignment = 3, - tooltip = "Click button to remove all clues from all investigators", - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={0,0,0,0} - }) - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function removeAllPlayerClues() - p1ClueCounter.call("removeAllClues") - p2ClueCounter.call("removeAllClues") - p3ClueCounter.call("removeAllClues") - p4ClueCounter.call("removeAllClues") -end - - -function reloadAll() - removeAll() - createAll() - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function updateVal() - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = "Click button to remove all clues from all investigators" - }) - self.editButton({ - index = 0, - value = tostring(val), - - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() -end +MIN_VALUE = -99 +MAX_VALUE = 999 + +function onload(saved_data) + light_mode = false + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + p1ClueCounter = getObjectFromGUID("37be78") + p2ClueCounter = getObjectFromGUID("1769ed") + p3ClueCounter = getObjectFromGUID("032300") + p4ClueCounter = getObjectFromGUID("d86b7c") + + timerID = self.getGUID()..math.random(9999999999999) + Timer.create({ + identifier=timerID, + function_name="totalCounters", function_owner=self, + repetitions=0, delay=1 + }) + createAll() +end + +function loadPlayerCounters() + p1ClueCounter = getObjectFromGUID("37be78") + p2ClueCounter = getObjectFromGUID("1769ed") + p3ClueCounter = getObjectFromGUID("032300") + p4ClueCounter = getObjectFromGUID("d86b7c") +end + + +function totalCounters() + if p1ClueCounter == nil or p2ClueCounter == nil or p3ClueCounter == nil or p4ClueCounter == nil then + loadPlayerCounters() + end + local p1ClueCount = p1ClueCounter.getVar("exposedValue") + local p2ClueCount = p2ClueCounter.getVar("exposedValue") + local p3ClueCount = p3ClueCounter.getVar("exposedValue") + local p4ClueCount = p4ClueCounter.getVar("exposedValue") + val = tonumber(p1ClueCount) + tonumber(p2ClueCount) + tonumber(p3ClueCount) + tonumber(p4ClueCount) + updateVal() + updateSave() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0.5, 0.5, 0.5, 95} + + if light_mode then + f_color = {1,1,1,95} + else + f_color = {0,0,0,100} + end + + self.createButton({ + label=tostring(val), + click_function="removeAllPlayerClues", + function_owner=self, + position={0,0.05,0}, + height=600, + width=1000, + alignment = 3, + tooltip = "Click button to remove all clues from all investigators", + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={0,0,0,0} + }) + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function removeAllPlayerClues() + p1ClueCounter.call("removeAllClues") + p2ClueCounter.call("removeAllClues") + p3ClueCounter.call("removeAllClues") + p4ClueCounter.call("removeAllClues") +end + + +function reloadAll() + removeAll() + createAll() + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function updateVal() + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = "Click button to remove all clues from all investigators" + }) + self.editButton({ + index = 0, + value = tostring(val), + + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() +end function onDestroy() Timer.destroy(timerID) diff --git a/unpacked/Custom_Token Playarea 721ba2.ttslua b/unpacked/Custom_Token Playarea 721ba2.ttslua index 4f133e507..8eefcaa64 100644 --- a/unpacked/Custom_Token Playarea 721ba2.ttslua +++ b/unpacked/Custom_Token Playarea 721ba2.ttslua @@ -1,214 +1,214 @@ --- set true to enable debug logging -DEBUG = false - --- we use this to turn off collision handling (for clue spawning) --- until after load is complete (probably a better way to do this) -COLLISION_ENABLED = false - --- TODO get the log function from global instead --- log = Global.call('getLogFunction', this) -function getLogFunction(object) - return function (message) - if DEBUG then - print(message) - end - end -end - -log = getLogFunction(self) - -function onload(save_state) - self.interactable = DEBUG - local dataHelper = getObjectFromGUID('708279') - LOCATIONS = dataHelper.getTable('LOCATIONS_DATA') - - TOKEN_PLAYER_ONE = Global.getTable('tokenplayerone') - COUNTER = getObjectFromGUID('f182ee') - log('attempting to load state: ' .. save_state) - if save_state ~= '' then - SPAWNED_LOCATION_GUIDS = JSON.decode(save_state) - end - - COLLISION_ENABLED = true -end - -function onSave() - local spawned_locations = JSON.encode(SPAWNED_LOCATION_GUIDS) - self.script_state = spawned_locations -end - ---[[ -records locations we have spawned clues for, we write this to the save -file onsave() so we don't spawn clues again after a load -]] -SPAWNED_LOCATION_GUIDS = {} - -function isAlreadySpawned(object) - return SPAWNED_LOCATION_GUIDS[object.getGUID()] ~= nil -end - -function markSpawned(object) - SPAWNED_LOCATION_GUIDS[object.getGUID()] = 1 -end - -function buildKey(object) - return object.getName() .. '_' .. object.getGUID() -end - --- try the compound key then the name alone as default -function getLocation(object) - return LOCATIONS[buildKey(object)] or LOCATIONS[object.getName()] -end - -function isLocationWithClues(object) - return getLocation(object) ~= nil -end - ---[[ -Return the number of clues to spawn on this location -]] -function getClueCount(object, isFaceDown, playerCount) - if not isLocationWithClues(object) then - error('attempted to get clue for unexpected object: ' .. object.getName()) - end - local details = getLocation(object) - log(object.getName() .. ' : ' .. details['type'] .. ' : ' .. details['value'] .. ' : ' .. details['clueSide']) - if ((isFaceDown and details['clueSide'] == 'back') - or (not isFaceDown and details['clueSide'] == 'front')) then - if details['type'] == 'fixed' then - return details['value'] - elseif details['type'] == 'perPlayer' then - return details['value'] * playerCount - end - error('unexpected location type: ' .. details['type']) - end - return 0 -end - -function spawnToken(position, number) - local obj_parameters = { - position = position, - rotation = {3.87674022, -90, 0.239081308} - } - local custom = { - thickness = 0.1, - stackable = true - } - - if number == '1' or number == '2' then - obj_parameters.type = 'Custom_Token' - custom.merge_distance = 5.0 - local token = spawnObject(obj_parameters) - if number == '1' then - custom.image = TOKEN_PLAYER_ONE.damageone - token.setCustomObject(custom) - token.scale {0.17, 1, 0.17} - return token - end - - if number == '2' then - custom.image = TOKEN_PLAYER_ONE.damagethree - token.setCustomObject(custom) - token.scale {0.18, 1, 0.18} - return token - end - end - - if number == '3' or number == '4' then - obj_parameters.type = 'Custom_Tile' - custom.type = 2 - local token = spawnObject(obj_parameters) - if number == '3' then - custom.image = TOKEN_PLAYER_ONE.clue - custom.image_bottom = TOKEN_PLAYER_ONE.doom - token.setCustomObject(custom) - token.scale {0.25, 1, 0.25} - token.use_snap_points=false - return token - end - - if number == '4' then - custom.image = TOKEN_PLAYER_ONE.doom - custom.image_bottom = TOKEN_PLAYER_ONE.clue - token.setCustomObject(custom) - token.scale {0.25, 1, 0.25} - token.use_snap_points=false - return token - end - end - -end - - -function spawnCluesAtLocation(clueCount, collision_info) - local object = collision_info.collision_object - if isAlreadySpawned(object) then - error('tried to spawn clue for already spawned location:' .. object.getName()) - end - - local obj_parameters = {} - obj_parameters.type = 'Custom_Token' - obj_parameters.position = { - object.getPosition()[1], - object.getPosition()[2] + 1, - object.getPosition()[3] - } - - log('spawning clues for ' .. object.getName() .. '_' .. object.getGUID()) - local playerCount = COUNTER.getVar('val') - log('player count is ' .. playerCount .. ', clue count is ' .. clueCount) - -- mark this location as spawned, can't happen again - markSpawned(object) - i = 0 - while i < clueCount do - if i < 4 then - obj_parameters.position = { - collision_info.collision_object.getPosition()[1] + 0.3, - collision_info.collision_object.getPosition()[2] + 0.2, - collision_info.collision_object.getPosition()[3] - 0.8 + (0.55 * i) - } - elseif i < 8 then - obj_parameters.position = { - collision_info.collision_object.getPosition()[1] + 0.85, - collision_info.collision_object.getPosition()[2] + 0.2, - collision_info.collision_object.getPosition()[3] - 3 + (0.55 * i) - } - else - obj_parameters.position = { - collision_info.collision_object.getPosition()[1] + 0.575, - collision_info.collision_object.getPosition()[2] + 0.4, - collision_info.collision_object.getPosition()[3] - 5.2 + (0.55 * i)} - end - spawnToken(obj_parameters.position, '3') - i = i + 1 - end -end - - -function updateLocations(args) - local custom_data_helper = getObjectFromGUID(args[1]) - data_locations = custom_data_helper.getTable("LOCATIONS_DATA") - for k, v in pairs(data_locations) do - LOCATIONS[k] = v - end -end - -function onCollisionEnter(collision_info) - -- short circuit all collision stuff until we've loaded state - if not COLLISION_ENABLED then - return - end - - -- check if we should spawn clues here - local object = collision_info.collision_object - if isLocationWithClues(object) and not isAlreadySpawned(object) then - -- this isn't an either/or as down/up here means at a relatively low angle - -- local isFaceUp = not object.is_face_down - -- local isFaceDown = (object.getRotation()[3] > 160 and object.getRotation()[3] < 200) - local playerCount = COUNTER.getVar('val') - local clueCount = getClueCount(object, object.is_face_down, playerCount) - if clueCount > 0 then - spawnCluesAtLocation(clueCount, collision_info) - end - end +-- set true to enable debug logging +DEBUG = false + +-- we use this to turn off collision handling (for clue spawning) +-- until after load is complete (probably a better way to do this) +COLLISION_ENABLED = false + +-- TODO get the log function from global instead +-- log = Global.call('getLogFunction', this) +function getLogFunction(object) + return function (message) + if DEBUG then + print(message) + end + end +end + +log = getLogFunction(self) + +function onload(save_state) + self.interactable = DEBUG + local dataHelper = getObjectFromGUID('708279') + LOCATIONS = dataHelper.getTable('LOCATIONS_DATA') + + TOKEN_PLAYER_ONE = Global.getTable('tokenplayerone') + COUNTER = getObjectFromGUID('f182ee') + log('attempting to load state: ' .. save_state) + if save_state ~= '' then + SPAWNED_LOCATION_GUIDS = JSON.decode(save_state) + end + + COLLISION_ENABLED = true +end + +function onSave() + local spawned_locations = JSON.encode(SPAWNED_LOCATION_GUIDS) + self.script_state = spawned_locations +end + +--[[ +records locations we have spawned clues for, we write this to the save +file onsave() so we don't spawn clues again after a load +]] +SPAWNED_LOCATION_GUIDS = {} + +function isAlreadySpawned(object) + return SPAWNED_LOCATION_GUIDS[object.getGUID()] ~= nil +end + +function markSpawned(object) + SPAWNED_LOCATION_GUIDS[object.getGUID()] = 1 +end + +function buildKey(object) + return object.getName() .. '_' .. object.getGUID() +end + +-- try the compound key then the name alone as default +function getLocation(object) + return LOCATIONS[buildKey(object)] or LOCATIONS[object.getName()] +end + +function isLocationWithClues(object) + return getLocation(object) ~= nil +end + +--[[ +Return the number of clues to spawn on this location +]] +function getClueCount(object, isFaceDown, playerCount) + if not isLocationWithClues(object) then + error('attempted to get clue for unexpected object: ' .. object.getName()) + end + local details = getLocation(object) + log(object.getName() .. ' : ' .. details['type'] .. ' : ' .. details['value'] .. ' : ' .. details['clueSide']) + if ((isFaceDown and details['clueSide'] == 'back') + or (not isFaceDown and details['clueSide'] == 'front')) then + if details['type'] == 'fixed' then + return details['value'] + elseif details['type'] == 'perPlayer' then + return details['value'] * playerCount + end + error('unexpected location type: ' .. details['type']) + end + return 0 +end + +function spawnToken(position, number) + local obj_parameters = { + position = position, + rotation = {3.87674022, -90, 0.239081308} + } + local custom = { + thickness = 0.1, + stackable = true + } + + if number == '1' or number == '2' then + obj_parameters.type = 'Custom_Token' + custom.merge_distance = 5.0 + local token = spawnObject(obj_parameters) + if number == '1' then + custom.image = TOKEN_PLAYER_ONE.damageone + token.setCustomObject(custom) + token.scale {0.17, 1, 0.17} + return token + end + + if number == '2' then + custom.image = TOKEN_PLAYER_ONE.damagethree + token.setCustomObject(custom) + token.scale {0.18, 1, 0.18} + return token + end + end + + if number == '3' or number == '4' then + obj_parameters.type = 'Custom_Tile' + custom.type = 2 + local token = spawnObject(obj_parameters) + if number == '3' then + custom.image = TOKEN_PLAYER_ONE.clue + custom.image_bottom = TOKEN_PLAYER_ONE.doom + token.setCustomObject(custom) + token.scale {0.25, 1, 0.25} + token.use_snap_points=false + return token + end + + if number == '4' then + custom.image = TOKEN_PLAYER_ONE.doom + custom.image_bottom = TOKEN_PLAYER_ONE.clue + token.setCustomObject(custom) + token.scale {0.25, 1, 0.25} + token.use_snap_points=false + return token + end + end + +end + + +function spawnCluesAtLocation(clueCount, collision_info) + local object = collision_info.collision_object + if isAlreadySpawned(object) then + error('tried to spawn clue for already spawned location:' .. object.getName()) + end + + local obj_parameters = {} + obj_parameters.type = 'Custom_Token' + obj_parameters.position = { + object.getPosition()[1], + object.getPosition()[2] + 1, + object.getPosition()[3] + } + + log('spawning clues for ' .. object.getName() .. '_' .. object.getGUID()) + local playerCount = COUNTER.getVar('val') + log('player count is ' .. playerCount .. ', clue count is ' .. clueCount) + -- mark this location as spawned, can't happen again + markSpawned(object) + i = 0 + while i < clueCount do + if i < 4 then + obj_parameters.position = { + collision_info.collision_object.getPosition()[1] + 0.3, + collision_info.collision_object.getPosition()[2] + 0.2, + collision_info.collision_object.getPosition()[3] - 0.8 + (0.55 * i) + } + elseif i < 8 then + obj_parameters.position = { + collision_info.collision_object.getPosition()[1] + 0.85, + collision_info.collision_object.getPosition()[2] + 0.2, + collision_info.collision_object.getPosition()[3] - 3 + (0.55 * i) + } + else + obj_parameters.position = { + collision_info.collision_object.getPosition()[1] + 0.575, + collision_info.collision_object.getPosition()[2] + 0.4, + collision_info.collision_object.getPosition()[3] - 5.2 + (0.55 * i)} + end + spawnToken(obj_parameters.position, '3') + i = i + 1 + end +end + + +function updateLocations(args) + local custom_data_helper = getObjectFromGUID(args[1]) + data_locations = custom_data_helper.getTable("LOCATIONS_DATA") + for k, v in pairs(data_locations) do + LOCATIONS[k] = v + end +end + +function onCollisionEnter(collision_info) + -- short circuit all collision stuff until we've loaded state + if not COLLISION_ENABLED then + return + end + + -- check if we should spawn clues here + local object = collision_info.collision_object + if isLocationWithClues(object) and not isAlreadySpawned(object) then + -- this isn't an either/or as down/up here means at a relatively low angle + -- local isFaceUp = not object.is_face_down + -- local isFaceDown = (object.getRotation()[3] > 160 and object.getRotation()[3] < 200) + local playerCount = COUNTER.getVar('val') + local clueCount = getClueCount(object, object.is_face_down, playerCount) + if clueCount > 0 then + spawnCluesAtLocation(clueCount, collision_info) + end + end end \ No newline at end of file diff --git a/unpacked/Custom_Token Resources 4406f0.ttslua b/unpacked/Custom_Token Resources 4406f0.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Token Resources 4406f0.ttslua +++ b/unpacked/Custom_Token Resources 4406f0.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Resources 816d84.ttslua b/unpacked/Custom_Token Resources 816d84.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Token Resources 816d84.ttslua +++ b/unpacked/Custom_Token Resources 816d84.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Resources a4b60d.ttslua b/unpacked/Custom_Token Resources a4b60d.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Token Resources a4b60d.ttslua +++ b/unpacked/Custom_Token Resources a4b60d.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file diff --git a/unpacked/Custom_Token Resources cd15ac.ttslua b/unpacked/Custom_Token Resources cd15ac.ttslua index 167a90f72..df6f93a6c 100644 --- a/unpacked/Custom_Token Resources cd15ac.ttslua +++ b/unpacked/Custom_Token Resources cd15ac.ttslua @@ -1,132 +1,132 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 - -function onload(saved_data) - light_mode = true - val = 0 - - if saved_data ~= "" then - local loaded_data = JSON.decode(saved_data) - light_mode = loaded_data[1] - val = loaded_data[2] - end - - createAll() -end - -function updateSave() - local data_to_save = {light_mode, val} - saved_data = JSON.encode(data_to_save) - self.script_state = saved_data -end - -function createAll() - s_color = {0,0,0,100} +MIN_VALUE = -99 +MAX_VALUE = 999 - if light_mode then - f_color = {1,1,1,100} - else - f_color = {0,0,0,100} - end - - - - self.createButton({ - label=tostring(val), - click_function="add_subtract", - function_owner=self, - position={0,0.05,0.1}, - height=600, - width=1000, - alignment = 3, - scale={x=1.5, y=1.5, z=1.5}, - font_size=600, - font_color=f_color, - color={1,1,1,0} - }) - - - - - if light_mode then - lightButtonText = "[ Set dark ]" - else - lightButtonText = "[ Set light ]" - end - -end - -function removeAll() - self.removeInput(0) - self.removeInput(1) - self.removeButton(0) - self.removeButton(1) - self.removeButton(2) -end - -function reloadAll() - removeAll() - createAll() - - updateSave() -end - -function swap_fcolor(_obj, _color, alt_click) - light_mode = not light_mode - reloadAll() -end - -function swap_align(_obj, _color, alt_click) - center_mode = not center_mode - reloadAll() -end - -function editName(_obj, _string, value) - self.setName(value) - setTooltips() -end - -function add_subtract(_obj, _color, alt_click) - mod = alt_click and -1 or 1 - new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) - if val ~= new_value then - val = new_value - updateVal() - updateSave() - end -end - -function updateVal() - - self.editButton({ - index = 0, - label = tostring(val), - - }) -end - -function reset_val() - val = 0 - updateVal() - updateSave() -end - -function setTooltips() - self.editInput({ - index = 0, - value = self.getName(), - tooltip = ttText - }) - self.editButton({ - index = 0, - value = tostring(val), - tooltip = ttText - }) -end - -function null() -end - -function keepSample(_obj, _string, value) - reloadAll() +function onload(saved_data) + light_mode = true + val = 0 + + if saved_data ~= "" then + local loaded_data = JSON.decode(saved_data) + light_mode = loaded_data[1] + val = loaded_data[2] + end + + createAll() +end + +function updateSave() + local data_to_save = {light_mode, val} + saved_data = JSON.encode(data_to_save) + self.script_state = saved_data +end + +function createAll() + s_color = {0,0,0,100} + + if light_mode then + f_color = {1,1,1,100} + else + f_color = {0,0,0,100} + end + + + + self.createButton({ + label=tostring(val), + click_function="add_subtract", + function_owner=self, + position={0,0.05,0.1}, + height=600, + width=1000, + alignment = 3, + scale={x=1.5, y=1.5, z=1.5}, + font_size=600, + font_color=f_color, + color={1,1,1,0} + }) + + + + + if light_mode then + lightButtonText = "[ Set dark ]" + else + lightButtonText = "[ Set light ]" + end + +end + +function removeAll() + self.removeInput(0) + self.removeInput(1) + self.removeButton(0) + self.removeButton(1) + self.removeButton(2) +end + +function reloadAll() + removeAll() + createAll() + + updateSave() +end + +function swap_fcolor(_obj, _color, alt_click) + light_mode = not light_mode + reloadAll() +end + +function swap_align(_obj, _color, alt_click) + center_mode = not center_mode + reloadAll() +end + +function editName(_obj, _string, value) + self.setName(value) + setTooltips() +end + +function add_subtract(_obj, _color, alt_click) + mod = alt_click and -1 or 1 + new_value = math.min(math.max(val + mod, MIN_VALUE), MAX_VALUE) + if val ~= new_value then + val = new_value + updateVal() + updateSave() + end +end + +function updateVal() + + self.editButton({ + index = 0, + label = tostring(val), + + }) +end + +function reset_val() + val = 0 + updateVal() + updateSave() +end + +function setTooltips() + self.editInput({ + index = 0, + value = self.getName(), + tooltip = ttText + }) + self.editButton({ + index = 0, + value = tostring(val), + tooltip = ttText + }) +end + +function null() +end + +function keepSample(_obj, _string, value) + reloadAll() end \ No newline at end of file