Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////
- // Yeen go WHOOP! //
- // Nori Ovis 2020 //
- //////////////////////////////////////////////////////////
- //System stuff
- integer noisetoggle = FALSE; //If this is TRUE, respond to other yeen's sounds
- list noises = ["Pop"]; //Kinda easy-ish to add more later??? The actual noise function tries to use whatever you feed it
- list responddelays = [1.5, 0.5, 1.0]; //The minimum amount of time in seconds to wait before responding to a noise
- float respondchance = 0.7; //Chance to successfully trigger a response. 0.5 = 50%, 0.2 = 20%, etc.
- integer debug = FALSE; //Get debug messages?
- //Listen stuff
- integer respondhandle; //This listen handle is toggleable so it doesn't try to respond if the HUD is sitting on the ground
- integer respondchannel = -125834959; //This channel is for triggering responses
- integer gesturechannel = -1; //This channel is for users' gestures to trigger noises
- //Anti-spam
- float cooldown = 1.2; //How long of a period must elapse before noises can be triggered again
- float lastnoise; //The timestamp of the last time a noise was successfully triggered
- //There's not really much else to do here atm
- toggle(integer on)
- {
- integer i;
- for(i = 0; i < llGetNumberOfPrims() - 1; i++)
- {
- if(llList2String(llGetLinkPrimitiveParams(i, [PRIM_NAME]), 0) == "Noise Toggle") llSetLinkAlpha(i, (float)on, ALL_SIDES);
- }
- noisetoggle = on;
- if(debug) llOwnerSay("Responses: " + llList2String(["Off", "On"], on) + " (" + (string)llCeil(respondchance * 100) + "% chance)");
- return;
- }
- //This is after a successful percentage check if it's a response, otherwise 100% chance if triggered by the user
- triggernoise(string noise, integer causedbyself)
- {
- if(debug) llOwnerSay("Time since last noise: " + (string)llGetTime() + " seconds (" + (string)cooldown + "-second cooldown)");
- if(llGetTime() < cooldown) return;
- llResetTime();
- llListenControl(respondhandle, FALSE); //Prevent extra responses from piling up during llSleep()
- if(debug) llOwnerSay("Caused by self: " + llList2String(["No", "Yes"], causedbyself));
- if(!causedbyself)
- {
- float chosenminimum = llList2Float(responddelays, llCeil(llFrand(llGetListLength(responddelays))) - 1);
- llSleep(chosenminimum);
- }
- list validnoises;
- list validanims;
- integer noisenamelen = llStringLength(noise) - 1;
- integer i;
- for(i = 0; i < llGetInventoryNumber(INVENTORY_ALL); i++)
- {
- string currentitem = llGetInventoryName(INVENTORY_ALL, i);
- if(llGetSubString(currentitem, 0, noisenamelen) == noise)
- {
- if(llGetInventoryType(llGetInventoryName(INVENTORY_ALL, i)) == INVENTORY_SOUND) validnoises += llGetInventoryKey(currentitem);
- else if(llGetInventoryType(llGetInventoryName(INVENTORY_ALL, i)) == INVENTORY_ANIMATION) validanims += currentitem;
- }
- }
- if(llGetListLength(validnoises) > 0)
- {
- integer chosennoise = llCeil(llFrand(llGetListLength(validnoises) - 1));
- if(debug) llOwnerSay("Chose " + noise + " " + (string)chosennoise + "/" + (string)(llGetListLength(validnoises) - 1));
- llTriggerSound(llList2Key(validnoises, chosennoise), 1.0);
- if(noisetoggle/* && causedbyself*/) llSay(respondchannel, noise);
- }
- if(llGetListLength(validanims) > 0)
- {
- if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
- {
- llStartAnimation(llList2String(validanims, llCeil(llFrand(llGetListLength(validanims) - 1))));
- }
- }
- llListenControl(respondhandle, TRUE);
- }
- integer tryresponse()
- {
- float responsepercent = llFrand(1.0);
- if(debug) llOwnerSay("Response percentage scored " + (string)(100 - llCeil(responsepercent * 100)) + "% / " +
- (string)llCeil(respondchance * 100) + "% (" + llList2String(["Success", "Exceeded (Fail)"], responsepercent > respondchance) + ")");
- if(responsepercent > respondchance || !noisetoggle) return FALSE; //check chance
- else return TRUE;
- }
- default
- {
- state_entry()
- {
- toggle(TRUE);
- llListen(gesturechannel, "", "", "");
- if(llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
- }
- changed(integer chg)
- {
- if(chg & CHANGED_OWNER || chg & CHANGED_INVENTORY) llResetScript();
- }
- run_time_permissions(integer perm)
- {
- if(perm & PERMISSION_TAKE_CONTROLS)
- {
- llTakeControls(CONTROL_UP, TRUE, TRUE);
- respondhandle = llListen(respondchannel, "", "", "");
- }
- }
- control(key id, integer level, integer edge)
- {
- ;
- }
- attach(key a)
- {
- if(llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
- //If detached, turn off the response listen channel
- else llListenRemove(respondhandle);
- }
- touch_start(integer ts)
- {
- while(~--ts)
- {
- string name = llList2String(llGetLinkPrimitiveParams(llDetectedLinkNumber(ts), [PRIM_NAME]), 0);
- if(debug) llOwnerSay("Touched link with name: \"" + name + "\". Position in noises list = " + (string)llListFindList(noises, [name]) + " (-1 if not found)");
- //llOwnerSay("|" + llDumpList2String(noises, "|") + "|");
- if(name == "Noise Toggle") toggle(!noisetoggle);
- else if(~llListFindList(noises, [name])) triggernoise(name, TRUE);
- }
- }
- listen(integer c, string n, key id, string msg)
- {
- if(c == gesturechannel && id == llGetOwnerKey(llGetOwner()))
- {
- //Example gesture says "Cackle" on channel -1
- if(~llListFindList(noises, [msg])) triggernoise(msg, TRUE);
- else if(msg == "Debug") triggernoise("Cackle", FALSE); //Debug response
- }
- else if(c == respondchannel)
- {
- if(~llListFindList(noises, [msg]))
- {
- if(tryresponse()) triggernoise(msg, FALSE);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement