Jump to content

How do i make a "Cool down timer"?


LouiseDeBlois
 Share

You are about to reply to a thread that has been inactive for 4157 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

One last BIG question, i want to make my script, so, when it is touched (activated) It can NOT be activated again for a period of time.

// Rez an object on touch, with relative position, rotation, and velocity all described in the rezzing prim's coordinate system.
string object = "Rock"; // Name of object in inventory
vector relativePosOffset = <0.0, 0.0, 2.0>; // "Forward" and a little "above" this prim
vector relativeVel = <0.0, 0.0, 0.0>; // Traveling in this prim's "forward" direction at 1m/s
rotation relativeRot = <0.707107, 0.0, 0.0, 0.707107>; // Rotated 90 degrees on the x-axis compared to this prim
integer startParam = 50;

float MaxDist = 3.0;
string dist;
 
default
{
    state_entry()
    {
        dist = llGetSubString((string)MaxDist,0,(llSubStringIndex((string)MaxDist,".")+2));
       // llOwnerSay(dist);
    }
    
    touch_start(integer a)
         {
         key k = llDetectedKey(0);
        vector pos = llGetPos();
        if(llVecDist(pos,llDetectedPos(0))>MaxDist){
            llRegionSayTo(k,0,"Sorry, "+llGetDisplayName(k)+" but you must be no more than "+dist+" metres away for this to work");
            return;
        }
        else{
          llRegionSayTo(k,0,"You are within the maximum range");
          //do stuff
        }
    {
        vector myPos = llGetPos();
        rotation myRot = llGetRot();
 
        vector rezPos = myPos+relativePosOffset*myRot;
        vector rezVel = relativeVel*myRot;
        rotation rezRot = relativeRot*myRot;
 
        llRezObject(object, rezPos, rezVel, rezRot, startParam);
    }
}
}

 This is a working script, but, what do i add to it, to give it a "cool down" limit, so, example "10 minutes until it can be touched, OR, activated again" maybe with a visible hovering countdown timer?

Link to comment
Share on other sites

One way to do it is to send your script to a new state when it's touched, and then start a 10 minute timer in the new state.  If you don't have a touch_start event in the new state, it won't respond to a touch until the timer triggers and sends execution back to state default again.

  • Like 1
Link to comment
Share on other sites

Iv tried implimenting a script change state script, yet no idea how i shall do this....

 

default{    state_entry()    {        llSay(0,            "You either just saved the script after editing it"            + "\nand/or the script (re)entered the default state.");         llSetText("Click to change states", <1.0, 1.0, 1.0>, 1.0);    }     touch_end(integer num_detected)    {        // Note: NEVER do a state change from within a touch_start event -        // - that can lead to the next touch_start on return to this state to be missed.        // Here we do the state change safely, from within touch_end        state two;    }     state_exit()    {        llSay(0, "The script leaves the default state.");    }} state two{    state_entry()    {        llSay(0, "The script entered state 'two'");        state default;    }     state_exit()    {        llSay(0, "The script leaves state 'two'");    }}

 This is the script im trying to impliment.

Link to comment
Share on other sites

You can either do it the way Rolig described or like this where there is a timer to ignore the touches:

// Rez an object on touch, with relative position, rotation, and velocity all described in the rezzing prim's coordinate system.string object = "Rock"; // Name of object in inventoryvector relativePosOffset = <0.0, 0.0, 2.0>; // "Forward" and a little "above" this primvector relativeVel = <0.0, 0.0, 0.0>; // Traveling in this prim's "forward" direction at 1m/srotation relativeRot = <0.707107, 0.0, 0.0, 0.707107>; // Rotated 90 degrees on the x-axis compared to this priminteger startParam = 50;float MaxDist = 3.0;string dist;integer active = TRUE;float time = 15.0; //change this for how long to ignore touches default{    state_entry()    {        dist = llGetSubString((string)MaxDist,0,(llSubStringIndex((string)MaxDist,".")+2));       // llOwnerSay(dist);    }        touch_start(integer a)         {             if (active) {                 active = FALSE;                 llSetTimerEvent(time);                 key k = llDetectedKey(0);                 vector pos = llGetPos();                 if(llVecDist(pos,llDetectedPos(0))>MaxDist){                    llRegionSayTo(k,0,"Sorry, "+llGetDisplayName(k)+" but you must be no more than "+dist+" metres away for this to work");                    return;                 }                 else{                    llRegionSayTo(k,0,"You are within the maximum range");                    //do stuff                 }                 {                    vector myPos = llGetPos();                    rotation myRot = llGetRot()                    vector rezPos = myPos+relativePosOffset*myRot;                    vector rezVel = relativeVel*myRot                    rotation rezRot = relativeRot*myRot                    llRezObject(object, rezPos, rezVel, rezRot, startParam);                }            }        }timer(){    llSetTimerEvent(0);    active = TRUE;}}

 

Link to comment
Share on other sites

Sorry, you're right, this should avoid that problem

 

// Rez an object on touch, with relative position, rotation, and velocity all described in the rezzing prim's coordinate system.string object = "Rock"; // Name of object in inventoryvector relativePosOffset = <0.0, 0.0, 2.0>; // "Forward" and a little "above" this primvector relativeVel = <0.0, 0.0, 0.0>; // Traveling in this prim's "forward" direction at 1m/srotation relativeRot = <0.707107, 0.0, 0.0, 0.707107>; // Rotated 90 degrees on the x-axis compared to this priminteger startParam = 50;float MaxDist = 3.0;string dist;integer active = TRUE;float time = 15.0; //change this for how long to ignore touches default{    state_entry()    {        dist = llGetSubString((string)MaxDist,0,(llSubStringIndex((string)MaxDist,".")+2));       // llOwnerSay(dist);    }        touch_start(integer a)         {             if (active) {                  key k = llDetectedKey(0);                 vector pos = llGetPos();                 if(llVecDist(pos,llDetectedPos(0))>MaxDist){                    llRegionSayTo(k,0,"Sorry, "+llGetDisplayName(k)+" but you must be no more than "+dist+" metres away for this to work");                    return;                 }                 else{                    llRegionSayTo(k,0,"You are within the maximum range");                    //do stuff                 }                 {                    active = FALSE;                    llSetTimerEvent(time);                    vector myPos = llGetPos();                    rotation myRot = llGetRot()                    vector rezPos = myPos+relativePosOffset*myRot;                    vector rezVel = relativeVel*myRot                    rotation rezRot = relativeRot*myRot                    llRezObject(object, rezPos, rezVel, rezRot, startParam);                }            }        }timer(){    llSetTimerEvent(0);    active = TRUE;}}

 

Link to comment
Share on other sites

you can edit the time in the part near the top: 

float time = 15.0; //change this for how long to ignore touches

 it's in seconds so if you want 10 mins change it to:

float time = 600.0; //change this for how long to ignore touches

 A version with loading and ready messages:

// Rez an object on touch, with relative position, rotation, and velocity all described in the rezzing prim's coordinate system.string object = "Rock"; // Name of object in inventoryvector relativePosOffset = <0.0, 0.0, 2.0>; // "Forward" and a little "above" this primvector relativeVel = <0.0, 0.0, 0.0>; // Traveling in this prim's "forward" direction at 1m/srotation relativeRot = <0.707107, 0.0, 0.0, 0.707107>; // Rotated 90 degrees on the x-axis compared to this priminteger startParam = 50;float MaxDist = 3.0;string dist;integer active = TRUE;float time = 600.0; //change this for how long to ignore touches default{    state_entry()    {        dist = llGetSubString((string)MaxDist,0,(llSubStringIndex((string)MaxDist,".")+2));       // llOwnerSay(dist);    }        touch_start(integer a)         {             if (active) {                  key k = llDetectedKey(0);                 vector pos = llGetPos();                 if(llVecDist(pos,llDetectedPos(0))>MaxDist){                    llRegionSayTo(k,0,"Sorry, "+llGetDisplayName(k)+" but you must be no more than "+dist+" metres away for this to work");                    return;                 }                 else{                    llRegionSayTo(k,0,"You are within the maximum range");                    //do stuff                 }                 {                    active = FALSE;                    llSetTimerEvent(time);                    vector myPos = llGetPos();                    rotation myRot = llGetRot();                    vector rezPos = myPos+relativePosOffset*myRot;                    vector rezVel = relativeVel*myRot;                    rotation rezRot = relativeRot*myRot;                    llRezObject(object, rezPos, rezVel, rezRot, startParam);                    llWhisper(0, "Loading");                }            }        }timer(){    llSetTimerEvent(0);    active = TRUE;    llWhisper(0, "Ready");}}

 What do you mean by timer? Like a countdown in chat or something?

Link to comment
Share on other sites

Try something like this:

integer counter;integer delay = 15;default{	state_entry()			llSetText("I am touchable",<1.0,1.0,1.0>,1.0);	}	touch_end(integer total_number)	{		state untouchable;	}}state untouchable{	state_entry()	{		counter = delay;		llSetText("I am untouchable\nfor the next\n"+(string)counter+"\nseconds",<1.0,1.0,1.0>,1.0);		llSetTimerEvent(1.0);	}	timer()	{		--counter;		if(counter){//shorthand for if(counter != 0)			llSetText("I am untouchable\nfor the next\n"+(string)counter+"\nseconds",<1.0,1.0,1.0>,1.0);		}		else{			llSetTimerEvent(0.0);			state default;		}	}}

 

 ETA

The advantage of using a state change, rather than an integer switch, in an example like this is that the state change actually makes the object untouchable.   This way you don't have someone clicking away at an object that appears to be touchable (because of the mouse-pointer icon) and wondering why nothing's happening.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4157 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...