Advertisement
Strixursus

Pop Collective HUD code

Sep 5th, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. //////////////////////////////////////////////////////////
  2. // Yeen go WHOOP! //
  3. // Nori Ovis 2020 //
  4. //////////////////////////////////////////////////////////
  5.  
  6.  
  7. //System stuff
  8. integer noisetoggle = FALSE; //If this is TRUE, respond to other yeen's sounds
  9. list noises = ["Pop"]; //Kinda easy-ish to add more later??? The actual noise function tries to use whatever you feed it
  10. list responddelays = [1.5, 0.5, 1.0]; //The minimum amount of time in seconds to wait before responding to a noise
  11. float respondchance = 0.7; //Chance to successfully trigger a response. 0.5 = 50%, 0.2 = 20%, etc.
  12. integer debug = FALSE; //Get debug messages?
  13.  
  14. //Listen stuff
  15. integer respondhandle; //This listen handle is toggleable so it doesn't try to respond if the HUD is sitting on the ground
  16. integer respondchannel = -125834959; //This channel is for triggering responses
  17. integer gesturechannel = -1; //This channel is for users' gestures to trigger noises
  18.  
  19. //Anti-spam
  20. float cooldown = 1.2; //How long of a period must elapse before noises can be triggered again
  21. float lastnoise; //The timestamp of the last time a noise was successfully triggered
  22.  
  23. //There's not really much else to do here atm
  24. toggle(integer on)
  25. {
  26. integer i;
  27. for(i = 0; i < llGetNumberOfPrims() - 1; i++)
  28. {
  29. if(llList2String(llGetLinkPrimitiveParams(i, [PRIM_NAME]), 0) == "Noise Toggle") llSetLinkAlpha(i, (float)on, ALL_SIDES);
  30. }
  31. noisetoggle = on;
  32. if(debug) llOwnerSay("Responses: " + llList2String(["Off", "On"], on) + " (" + (string)llCeil(respondchance * 100) + "% chance)");
  33. return;
  34. }
  35.  
  36. //This is after a successful percentage check if it's a response, otherwise 100% chance if triggered by the user
  37. triggernoise(string noise, integer causedbyself)
  38. {
  39. if(debug) llOwnerSay("Time since last noise: " + (string)llGetTime() + " seconds (" + (string)cooldown + "-second cooldown)");
  40. if(llGetTime() < cooldown) return;
  41. llResetTime();
  42. llListenControl(respondhandle, FALSE); //Prevent extra responses from piling up during llSleep()
  43. if(debug) llOwnerSay("Caused by self: " + llList2String(["No", "Yes"], causedbyself));
  44. if(!causedbyself)
  45. {
  46. float chosenminimum = llList2Float(responddelays, llCeil(llFrand(llGetListLength(responddelays))) - 1);
  47. llSleep(chosenminimum);
  48. }
  49. list validnoises;
  50. list validanims;
  51. integer noisenamelen = llStringLength(noise) - 1;
  52. integer i;
  53. for(i = 0; i < llGetInventoryNumber(INVENTORY_ALL); i++)
  54. {
  55. string currentitem = llGetInventoryName(INVENTORY_ALL, i);
  56. if(llGetSubString(currentitem, 0, noisenamelen) == noise)
  57. {
  58. if(llGetInventoryType(llGetInventoryName(INVENTORY_ALL, i)) == INVENTORY_SOUND) validnoises += llGetInventoryKey(currentitem);
  59. else if(llGetInventoryType(llGetInventoryName(INVENTORY_ALL, i)) == INVENTORY_ANIMATION) validanims += currentitem;
  60. }
  61. }
  62. if(llGetListLength(validnoises) > 0)
  63. {
  64. integer chosennoise = llCeil(llFrand(llGetListLength(validnoises) - 1));
  65. if(debug) llOwnerSay("Chose " + noise + " " + (string)chosennoise + "/" + (string)(llGetListLength(validnoises) - 1));
  66. llTriggerSound(llList2Key(validnoises, chosennoise), 1.0);
  67. if(noisetoggle/* && causedbyself*/) llSay(respondchannel, noise);
  68. }
  69. if(llGetListLength(validanims) > 0)
  70. {
  71. if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
  72. {
  73. llStartAnimation(llList2String(validanims, llCeil(llFrand(llGetListLength(validanims) - 1))));
  74. }
  75. }
  76. llListenControl(respondhandle, TRUE);
  77. }
  78.  
  79. integer tryresponse()
  80. {
  81. float responsepercent = llFrand(1.0);
  82. if(debug) llOwnerSay("Response percentage scored " + (string)(100 - llCeil(responsepercent * 100)) + "% / " +
  83. (string)llCeil(respondchance * 100) + "% (" + llList2String(["Success", "Exceeded (Fail)"], responsepercent > respondchance) + ")");
  84. if(responsepercent > respondchance || !noisetoggle) return FALSE; //check chance
  85. else return TRUE;
  86. }
  87.  
  88. default
  89. {
  90. state_entry()
  91. {
  92. toggle(TRUE);
  93. llListen(gesturechannel, "", "", "");
  94. if(llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
  95. }
  96.  
  97. changed(integer chg)
  98. {
  99. if(chg & CHANGED_OWNER || chg & CHANGED_INVENTORY) llResetScript();
  100. }
  101.  
  102. run_time_permissions(integer perm)
  103. {
  104. if(perm & PERMISSION_TAKE_CONTROLS)
  105. {
  106. llTakeControls(CONTROL_UP, TRUE, TRUE);
  107. respondhandle = llListen(respondchannel, "", "", "");
  108. }
  109. }
  110.  
  111. control(key id, integer level, integer edge)
  112. {
  113. ;
  114. }
  115.  
  116. attach(key a)
  117. {
  118. if(llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
  119. //If detached, turn off the response listen channel
  120. else llListenRemove(respondhandle);
  121. }
  122.  
  123. touch_start(integer ts)
  124. {
  125. while(~--ts)
  126. {
  127. string name = llList2String(llGetLinkPrimitiveParams(llDetectedLinkNumber(ts), [PRIM_NAME]), 0);
  128. if(debug) llOwnerSay("Touched link with name: \"" + name + "\". Position in noises list = " + (string)llListFindList(noises, [name]) + " (-1 if not found)");
  129. //llOwnerSay("|" + llDumpList2String(noises, "|") + "|");
  130. if(name == "Noise Toggle") toggle(!noisetoggle);
  131. else if(~llListFindList(noises, [name])) triggernoise(name, TRUE);
  132. }
  133. }
  134.  
  135. listen(integer c, string n, key id, string msg)
  136. {
  137. if(c == gesturechannel && id == llGetOwnerKey(llGetOwner()))
  138. {
  139. //Example gesture says "Cackle" on channel -1
  140. if(~llListFindList(noises, [msg])) triggernoise(msg, TRUE);
  141. else if(msg == "Debug") triggernoise("Cackle", FALSE); //Debug response
  142. }
  143. else if(c == respondchannel)
  144. {
  145. if(~llListFindList(noises, [msg]))
  146. {
  147. if(tryresponse()) triggernoise(msg, FALSE);
  148. }
  149. }
  150. }
  151. }
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement