Advertisement
rorytorrance

slantix scoring frame 2.2

Apr 19th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //============================================================================================================
  2. // SLANTIX SCORING FRAME 2.2    by rory torrance
  3. //=== sizer ==================================================================================================
  4. float TS = 0.04;                    // tile size
  5. float HS = 0.02;                    // half tile size
  6. integer max = 38;                   // biggest size for frame
  7. vector Size;                        // current size of frame
  8. float SX;       float SY;           // last size of frame
  9. integer XX;     integer YY;         // size in spaces
  10. float SZ = 0.04;                    // height of frame stays the same
  11. float scale = 25;                   // factor to make ideal tile size = 1
  12. vector myPos;                       // current position of tile
  13. float margin = 0.95;                // physical margin size
  14. float marg1 = 0.1;                  // low limit of control margin
  15. float marg2 = 0.9;                  // hi limit of control margin
  16. vector Tcolr = <1, 1, 0.75>;        // color of display text
  17. //==== score =================================================================================================
  18. integer Symmetry = 1;               // default score variables
  19. integer Floors = 1;
  20. integer Rooms = 1;
  21. integer Tiles = 1;
  22. //==== input =================================================================================================
  23. integer listenHandle;                   // input handler
  24. integer Chanl = 99;
  25. string Result = "empty";                // results string
  26. //============================================================================================================
  27. default                                 // regular mode in which you adjust the frame size
  28. {   state_entry()
  29.     {   Size = llGetScale();                    // get size of frame prim
  30.         SX = Size.x*margin;                     // extract true x size of frame by shinking slightly
  31.         SY = Size.y*margin;                     // extract true y size of frame
  32.         XX = (integer)(SX*scale);               // find width in spaces
  33.         YY = (integer)(SY*scale);               // find height in spaces
  34.     }
  35.     touch_start(integer num)                                        // give instructions
  36.     {   integer Face = llDetectedTouchFace(0);                      // which face was touched
  37.         vector Place = llDetectedTouchST(0);                        // where it was touched
  38.         float PX = Place.x;                                         // separate out the x part
  39.         float PY = Place.y;                                         // separate out the y part
  40.         myPos = llGetPos();                                         // check the tile's position
  41.         if (Face == 0)          // +z                               // if its the front face
  42.         {   if ( PX >= marg2 )                                  // right
  43.             {   if (( PY >= marg1 ) && ( PY < 0.5))             // lo mid R  
  44.                 {   LESSX(<-HS, 0.0, 0.0>); }
  45.                 else if (( PY >= 0.5 ) && ( PY <= marg2))       // hi mid R  
  46.                 {   MOREX(<HS, 0.0, 0.0>); }
  47.                 else   { state inputter;  }                     // input variables
  48.             }
  49.             else if( PX <= 0.05 )                               // left
  50.             {   if (( PY >= marg1 ) && ( PY <= 0.5))            // lo mid L  
  51.                 {   LESSX(<HS, 0.0, 0.0>); }
  52.                 else if (( PY >= 0.5 ) && ( PY <= marg2))       // hi mid L  
  53.                 {   MOREX(<-HS, 0.0, 0.0>); }
  54.                 else    { state inputter; }                     // input variables
  55.             }
  56.             else if ( PY >= marg2 )                             // top
  57.             {   if (( PX > marg1 ) && ( PX <= 0.5))             // L top
  58.                 {   LESSY(<0.0, -HS, 0.0>); }
  59.                 else if (( PX > 0.5 ) && ( PX < marg2))         // R top
  60.                 {   MOREY(<0.0, HS, 0.0>); }
  61.             }
  62.             else if ( PY <= marg1 )                             // bottom
  63.             {   if (( PX > marg1 ) && ( PX <= 0.5))             // L botm
  64.                 {   LESSY(<0.0, HS, 0.0>); }
  65.                 else if (( PX > 0.5 ) && ( PX < marg2))         // R botm
  66.                 {   MOREY(<0.0, -HS, 0.0>); }
  67.             }
  68.         }
  69.     }
  70. }
  71. //============================================================================================================
  72. MOREX(vector P)                                         // increment frame X
  73. {   if (XX < max)                               // if not too  big
  74.     {   XX++;  finish(P); }                     // set position & scale
  75. }
  76. //============================================================================================================
  77. MOREY(vector P)                                         // increment frame Y
  78. {   if (YY < max)                               // if not too  big
  79.     {   YY++;  finish(P); }                     // set position & scale
  80. }
  81. //============================================================================================================
  82. LESSX(vector P)                                         // decrement frame X
  83. {   if (XX > 1)                                 // if not too  small
  84.     {   XX--;  finish(P); }                     // set position & scale
  85. }
  86. //============================================================================================================
  87. LESSY(vector P)                                         // decrement frame Y
  88. {   if (YY > 1)                                 // if not too  small
  89.     {   YY--;  finish(P); }                     // set position & scale
  90. }
  91. //============================================================================================================
  92. finish(vector P)                                        // set position & scale
  93. {   SX = XX/scale;  SY = YY/scale;              // convert spaces to metric
  94.     Size = <SX/margin, SY/margin, SZ>;          // adjust to outside of tiles
  95.     llSetScale(Size);                           // set the scale
  96.     llSetPos( myPos + P );                      // move the frame
  97. }
  98. //============================================================================================================
  99. integer contains(string haystack, string needle)    // finds substring in string
  100. {   return ~llSubStringIndex(haystack, needle);     // & returns it
  101. }
  102. //============================================================================================================
  103. state inputter                                        // mode in which you may input the score variables
  104. {   state_entry()                                            // give instructions
  105.     {   integer listenHandle = llListen(Chanl, "", NULL_KEY, "");
  106.         llWhisper(0, "Listening now on channel " + (string)Chanl + " \n"
  107.                 + "Say ON, OFF, BLANK to control text, or say\n"
  108.                 + "{slash Chanl space} tile-count, sym-level, # floors, # rooms."
  109.                 + "\nSeparate digits by commas, no spaces");
  110.     }
  111.     listen(integer channel, string name, key id, string message)
  112.     {   if (channel == Chanl)                                           // if its the right channel
  113.         {   llWhisper(0, "You said "+ message);                         // repeat the message to the user
  114.             if ( (message == "on") || (message == "ON") )               // ON turns on text display
  115.             {   llSetText( Result, Tcolr, 1.0);   }                     // display text
  116.             else if ( (message == "off") || (message == "OFF") )        // OFF turns off text display
  117.             {   llSetText( "", < 0.0, 0.0, 0.0 >, 1.0); }               // display NO text
  118.             else if ( (message == "blank") || (message == "BLANK") )    // BLANK resets text display
  119.             {   string Result = "empty";                                // reset results string
  120.                 llSetText( Result, Tcolr, 1.0);                         // display text
  121.             }
  122.             else if (contains( message, ","))                           // finds first comma if its score input
  123.             {   integer Index1 = llSubStringIndex(message, ",");        // set marker there
  124.                 string Rem1 = llGetSubString(message, Index1+1, -1);    // save rest of message
  125.                 string Targ  = llGetSubString(message, 0, Index1-1);    // get 1st[,] & string up "tile count"
  126.                 Tiles = (integer)Targ;                                  // save as TILES
  127.                 if (contains(Rem1, ","))                                // look for next comma
  128.                 {   integer Index2 = llSubStringIndex(Rem1, ",");           // set marker there
  129.                     string Rem2  = llGetSubString(Rem1, Index2+1, -1);      // save rest of text,
  130.                     Targ = llGetSubString(Rem1, 0, Index2-1);               // save next as target
  131.                     Symmetry = (integer)Targ;                               // save as SYM LEVEL
  132.                     if (contains(Rem2, ","))                                // look for next comma
  133.                     {   integer Index3 = llSubStringIndex(Rem2, ",");           // set marker there
  134.                         string Rem3 = llGetSubString(Rem2, Index3+1, -1);       // save rest of text
  135.                         Targ  = llGetSubString(Rem2, 0,  Index3-1);             // save next as target
  136.                         Floors = ((integer)Targ);                               // save  as FLOORS
  137.                         Rooms = ((integer)Rem3);                                // save rest as ROOMS
  138.                 }   }
  139.                 integer Score = Tiles*Symmetry*Floors*Rooms;            // <<<<<<<< EDIT FORMULA HERE <<
  140.                 Result = "Tiles=" + (string)Tiles +"\n"+
  141.                     "Sym.Levl=" + (string)Symmetry +"\n"+
  142.                     "Floors=" + (string)Floors + "\n"+
  143.                     "Rooms=" + (string)Rooms + "\n"+
  144.                     "SCORE=" + (string)Score;
  145.                 llSetText( Result, Tcolr, 1.0);                         // put results in display text
  146.         }   }
  147.         llListenRemove(listenHandle);                                   //     remove listen handles
  148.         state default;
  149. }   }
  150. //============================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement