Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A script to put in demo worn items to allow the purchaser a certain amount of time to try on the item. Once the time has expired it will detach and they can not wear it again.
- // make this script no mod so it can not be reset by the wearer.
- // can work for copy or no copy items
- // unless the user is going to copy and reattach this item a million times, this is a sufficient way to allow a user only a certain amount of time to view the worn demo.
- key creator = ""; // the uuid key of the creator, put it between the brackets. Used so that item wont detach and delete if the wearer is the creator.
- float time = 300.0; // time in seconds to allow the user to wear the demo. 300 seconds is 5 minutes.
- float elapsed_time;
- integer allow_timer = TRUE; // a boolean to make sure the timer does not restart after repeatedly attaching.
- integer allow_wearing = TRUE; // a boolean to allow the demo to be worn, if the boolean is false don't allow the item to be worn.
- integer tick;
- string FormatFloat(float f, integer num_decimals) // a function to cut trailing zeros from a float. Taken from this wiki: https://wiki.secondlife.com/wiki/User:Pedro_Oval/Float_formatting_functions
- {
- float rounding = (float)(".5e-" + (string)num_decimals) - 0.0000005;
- if (f < 0.0) f -= rounding; else f += rounding;
- string ret = llGetSubString((string)f, 0, num_decimals - 7);
- if ((float)ret == 0. && llGetSubString(ret, 0, 0) == "-")
- ret = llDeleteSubString(ret, 0, 0);
- if (! num_decimals) ret += "0";
- return ret;
- }
- default
- {
- state_entry()
- {
- // creator = llGetCreator(); // optional way to get the creator key. uncomment this line if you want to get the key of the creator this way
- tick = 0;
- elapsed_time = time - (float)tick;
- }
- on_rez(integer start_param)
- {
- integer at = llGetAttached(); // check if item is attached.
- if(at == 0) // if item is not attached either delete the item it is copy or stop the timer
- {
- llDie(); // if item is copy we can just delete it
- llOwnerSay("Please wear this item. Don't rez it.");
- // option for no copy items below. // comment out the llDie() above if item is no copy and uncomment the below lines.
- // you could also keep llDie() and delete the item if it is a free demo.
- // llSetTimerEvent(0.0);
- // allow_timer = TRUE;
- }
- }
- attach(key id)
- {
- if(id)
- {
- if(id != creator)
- {
- if(allow_timer == TRUE)
- {
- allow_timer = FALSE;
- llSetTimerEvent(1.0);
- }
- if(allow_wearing == TRUE)
- {
- float elapsed = elapsed_time/60;
- llOwnerSay("You have " + FormatFloat(elapsed,2) + " minutes to wear this demo item");
- }
- else
- {
- llOwnerSay("The time to view this item has expired.");
- llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
- }
- }
- }
- }
- timer()
- {
- ++tick;
- elapsed_time = time - (float)tick; // get elapsed time
- if(elapsed_time <= 0.0)
- {
- llSetTimerEvent(0.0);
- llOwnerSay("The time to view this item has expired.");
- allow_wearing = FALSE; // if time has expired dont allow item to beworn again.
- llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
- }
- }
- run_time_permissions(integer perm)
- {
- if(perm & PERMISSION_ATTACH)
- llDetachFromAvatar(); //detach from avatar after elapsed time
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement