SHARE
TWEET

[SL] Yadni's Emoter Hud Rework

N3K0 Jun 29th, 2019 (edited) 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //------------------------------------------------------------------------------
  2. // YADNI'S EMOTER HUD REWORK, reworked by ᴎѯᴋᴓ-ᴓו [141 LINES]
  3. //------------------------------------------------------------------------------
  4. // This script replaces the 30+ original scripts with a single optimised linkset
  5. // -aware version. Original scripts are (c) forever Yadni Monde. I wrote this
  6. // code because I love the HUD, so don't hate me. Memory comparison:
  7. //
  8. //     o [03:39] 2005.DEC.31 'YadNi s EmoterHUD' uses 688128 byte(s) in 39
  9. //               script(s).
  10. //     o [03:40] 2019.06.29 'YadNi's Emoter HUD -single-' uses 32768 byte(s)
  11. //               in 1 script(s).
  12. //
  13. //------------------------------------------------------------------------------
  14. // To fit an existing "YadNi s EmoterHUD" with this script, perform the following
  15. // tasks:
  16. //
  17. //     o Delete all legacy scripts from the HUD;
  18. //     o Rename all the HUD buttons so their names are "1" through "19".
  19. //       Do this from left to right, top to bottom,so button "19" is the last
  20. //       button and "1" is the button immediately to the left of the little
  21. //       blue root prim.
  22. //     o Drop this script into the little blue root prim.
  23. //     o All done!
  24. //
  25. //------------------------------------------------------------------------------
  26. vector  on_colour  =<1,0.5,0>;
  27. vector  off_colour =<1,1,1>;
  28. integer num_buttons=19;
  29. //------------------------------------------------------------------------------
  30. list morphs=[/*Morph #0 is unused but must be kept in this list!*/
  31. "","express_tongue_out","express_wink_emote","express_kiss",
  32. "express_toothsmile","express_smile","express_laugh_emote","express_open_mouth",
  33. "express_disdain","express_repulsed_emote","express_anger_emote",
  34. "express_bored_emote","express_sad_emote","express_cry_emote",
  35. "express_embarrassed_emote","express_frown","express_shrug_emote",
  36. "express_afraid_emote","express_worry_emote","express_surprise_emote"];
  37. //------------------------------------------------------------------------------
  38. integer F(string name){integer i=llGetNumberOfPrims();
  39.     while(i>1){if(llGetLinkName(i)==name){return i;}i--;}return FALSE;
  40. }
  41. //------------------------------------------------------------------------------
  42. RefButt(string butt){
  43.  integer prim=F(butt);if(prim<2){return;}
  44.  vector orig=llList2Vector(llGetLinkPrimitiveParams(prim,[PRIM_POS_LOCAL]),0);
  45.   if(open){chg+=[PRIM_LINK_TARGET,prim,PRIM_POS_LOCAL,orig+<0.75,0,0>];}else
  46.           {chg+=[PRIM_LINK_TARGET,prim,PRIM_POS_LOCAL,orig-<0.75,0,0>];}
  47. }
  48. //------------------------------------------------------------------------------
  49. HudRefresh(){
  50.   integer i=1;while(i<=num_buttons){RefButt((string)i);i++;}Bang();
  51. }
  52. //------------------------------------------------------------------------------
  53. ButtonToggle(string butt,integer st){
  54.   integer prim=F(butt);if(prim<2){return;}
  55.   if(st){chg+=[PRIM_LINK_TARGET,prim,PRIM_COLOR,ALL_SIDES,on_colour,1];}else
  56.         {chg+=[PRIM_LINK_TARGET,prim,PRIM_COLOR,ALL_SIDES,off_colour,1];}
  57.   Bang();
  58. }
  59.  
  60. Animation(string n,integer add){
  61.   if(llGetPermissionsKey()!=llGetOwner()){return;}
  62.   string ANIM=llList2String(morphs,(integer)n);if(ANIM==""){return;}
  63.   if(add){llStartAnimation(ANIM);}else{llStopAnimation(ANIM);}
  64. }
  65. //------------------------------------------------------------------------------
  66. ButtonFlip(string butt){
  67.   integer prim=F(butt);if(prim<2){return;}
  68.   if(!IsOn(butt)){Animation(butt,TRUE);Set(butt,prim,TRUE);}else
  69.                  {Animation(butt,FALSE);Set(butt,prim,FALSE);}
  70. }
  71. //------------------------------------------------------------------------------
  72. ButtonUpdate(string butt){
  73.   if(llGetPermissionsKey()!=llGetOwner()){return;}
  74.   integer prim=F(butt);if(prim<2){return;}
  75.   if(IsOn(butt)){Animation(butt,FALSE);Animation(butt,TRUE);}
  76. }
  77. //------------------------------------------------------------------------------
  78. Bang(){
  79.   if(chg!=[]){llSetLinkPrimitiveParamsFast(2,chg);chg=[];}
  80. }
  81. //------------------------------------------------------------------------------
  82. integer IsOn(string butt){
  83.   integer id=(integer)butt;
  84.   return(llList2Integer(states,id)!=0);
  85. }
  86. //------------------------------------------------------------------------------
  87. integer NoneAreOn(){return(llListFindList(states,[TRUE])<0);}
  88. Set(string butt,integer prim,integer on){
  89.   if(prim<2){return;}
  90.   integer id=(integer)butt;
  91.   if(on){states=llListReplaceList(states,[1],id,id);}else
  92.         {states=llListReplaceList(states,[0],id,id);}
  93.   ButtonToggle(butt,on);Bang();
  94.   /*FIX: Turn off the timer when not in use.*/
  95.   if(NoneAreOn()){llSetTimerEvent(0);}else{llSetTimerEvent(0.5);}
  96. }
  97. //------------------------------------------------------------------------------
  98. integer open=TRUE;list chg=[];
  99. string sound="9a17201e-8266-a21c-4070-06023dabebcb";
  100. list states=[FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
  101. FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE];
  102. //------------------------------------------------------------------------------
  103. default {
  104.   timer(){
  105.     integer i=1;while(i<=num_buttons){ButtonUpdate((string)i);i++;}
  106.   }
  107.   state_entry(){
  108.     llSetMemoryLimit(32768);
  109.     integer i=1;while(i<=num_buttons){ButtonToggle((string)i,FALSE);i++;}
  110.     Bang();llSetTimerEvent(0);
  111.   }
  112.   changed(integer mew){
  113.     if(mew & CHANGED_OWNER){llResetScript();}
  114.   }
  115.   run_time_permissions(integer mew){
  116.   }
  117.   attach(key j){
  118.     if((j!=NULL_KEY)&&(llGetAttached()>0)){
  119.       llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
  120.     }
  121.   }
  122.   touch_start(integer total_number){
  123.     if(llGetPermissionsKey()!=llGetOwner()){
  124.       llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
  125.     }
  126.     integer l=llDetectedLinkNumber(0);
  127.     string  n=llGetLinkName(l);
  128.     if(l==1){
  129.       open=!open;
  130.       llTriggerSound(sound,1.0);
  131.       if(open){
  132.         llOwnerSay( "EmoterHUD On");
  133.         HudRefresh();
  134.       }else{
  135.         llOwnerSay( "EmoterHUD Off");
  136.         HudRefresh();
  137.       }
  138.       return;
  139.     }
  140.     ButtonFlip(n);
  141.   }
  142. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top