Jump to content

Code for tracking an avatar's time in region - used for making levels


SEMaster Aftermath
 Share

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

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

Recommended Posts

Can anyone please help me with how to track the amount of time an avatar has been in a region? Here is what I am trying to work on:

I want to make a HUD where people can gain experience based on the amount of time they are in the region and wearing the HUD. For example, every x number of minutes (or seconds if lsl prefers seconds) a person is in the region and has their HUD on, their "experience" level will increase by 1.

Thanks for any help on this.

First time poster in the community, so my apologies if this is the the appropriate place to ask for this kind of help.

Link to comment
Share on other sites

Roughly:

string gRegionName = "My awesome RP sim!";
integer gTimeSpent;
integer gTimeAttached;

default
{  touch_start(integer n)
   {   llSay(0,"HUD has been attached for: "+
          (string)(gTimeSpent+llGetUnixTime()-gTimeAttached)+
             " seconds.");
   }
   attach(key ID)
   {  if(ID) // was attached.
      {  if(llGetRegionName()!=gRegionName)
         {  llRequestPermissions(ID,PERMISSION_ATTACH);
         }
         // set attached time in any case, to simplify detach logic.
         gTimeAttached = llGetUnixTime();
      }else // was detached.
      {  gTimeSpent+= llGetUnixTime()-gTimeAttached;
      }
   }
   changed(integer c)
   {  if(c&CHANGED_REGION)
      {  llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
      }
   }
   run_time_permissions(integer perms)
   {  if(perms&PERMISSION_ATTACH)
      {   llDetachFromAvatar();
      }
   }
}

(untested, may have bugs and syntax errors)

It's probably possible to do it without forcing the HUD to detach when not on the region, but this seems like the most straight-forward method.

Actually using that time value in some sort of meaningful way is where it gets complicated.

Edited by Quistess Alpha
Link to comment
Share on other sites

Thank you for the help. My only concern with this is I think (I am testing it in world) that when the person attaches the HUD at the beginning, it clocks that time. If they take it off, and it is off for the next three months, then they put it back on...with the script know to not count the time that it was removed?

I was going to have people level up one level for every 3600 seconds they wear the HUD. The higher their level, the more abilities they have on the sim. When I tested it in world, at first it worked, then I removed it, went to another region, came back, and when I checked it said I was wearing the HUD for 416000000 something seconds (the amount of time from right now to unix time).

Link to comment
Share on other sites

15 minutes ago, SEMaster Aftermath said:

My only concern with this is I think (I am testing it in world) that when the person attaches the HUD at the beginning, it clocks that time. If they take it off, and it is off for the next three months, then they put it back on...with the script know to not count the time that it was removed?

Yup, I just tested it, the only issue I can see is that if it is detached before it is attached (i.e. you put the script in while it is attached to you, or edit it while it's on you) then the attach time never gets set to something reasonable. You'll want to set gTimeAttached to the current unix time in state_entry, and set the total time spent back to 0 when the owner changes.

Link to comment
Share on other sites

Hmm. It seems to continue counting when the HUD is detached. I wonder if it needs to store the "worn time" somewhere, and just start counting from there the next time the HUD is attached.

Actually, now that I think of it, a simple counter that goes up would do the trick also, instead of trying to use time. I know how to count and make things happen after a set amount of time, but is there a way to count upwards from zero (and then the saved previous sum) every time it is worn?

Perhaps this is just a limitation in SL.

Link to comment
Share on other sites

2 hours ago, SEMaster Aftermath said:

It seems to continue counting when the HUD is detached.

I suppose it would if the detach procedure doesn't fire before it's actually detached. A more foolproof method is indeed to just add to an accumulator on a timer:

string gRegionName = "My awesome RP sim!";
integer gTimeSpent;

default
{  state_entry()
   {   llSetTimerEvent(60.0);
   }
   timer()
   {   ++gTimeSpent; // gTimeSpent = gTimeSpent+1;
   }
   touch_start(integer n)
   {   llSay(0,"HUD has been attached for: "+
          (string)(gTimeSpent)+
             " minutes.");
   }
   // basically the same from this point:
   attach(key ID)
   {  if(ID) // was attached.
      {  if(llGetRegionName()!=gRegionName)
         {  llRequestPermissions(ID,PERMISSION_ATTACH);
         }
      }
   }
   changed(integer c)
   {  if(c&CHANGED_REGION)
      {  llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
      }
   }
   run_time_permissions(integer perms)
   {  if(perms&PERMISSION_ATTACH)
      {   llDetachFromAvatar();
      }
   }
}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 664 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...