Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Age Check

Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
04-20-2007 05:44
Use this script snippet to protect your creations of being abused by griefers.
Or just make sure the user has spent some time in SL before they may use your products.
Or...
Be creative ^^

CODE
// This is a simple method to verify the age of a person.
// It does not use all the fancy leap year detection and whatever stuff.
// It compensates for leap years by adding a quarter day to each full year.
// For everyday use the accuracy of +/- 1 to 2 days should be sufficient.

// Free Script. Do not remove this header or the comments if you plan to pass it on to others.
// This script may NOT be sold for monetary profit unless it is integrated in some other script
// you want or need an age check for.

// Enjoy.

key Query;

default
{

on_rez(integer X) {llResetScript();}

touch_start(integer X)
{
llSetText("Verifying your age...",<0,1,0>,1);
Query = llRequestAgentData(llDetectedKey(0),DATA_BORN);
}

dataserver(key QID,string Data)
{
if (QID == Query)
{
// The following variables are set to account for leap years and assume
// the days evenly distributed amongst the 12 months of a year.
float YrDays = 365.25;
float MnDays = YrDays / 12;
float DyInc = 1.0;
// This is the user's birthdate.
integer uYr = (integer)llGetSubString(Data,0,3);
integer uMn = (integer)llGetSubString(Data,5,6);
integer uDy = (integer)llGetSubString(Data,8,9);
float uXVal = uYr * YrDays + (uMn - 1) * MnDays + uDy * DyInc;
// This is today's date
Data = llGetDate();
integer Yr = (integer)llGetSubString(Data,0,3);
integer Mn = (integer)llGetSubString(Data,5,6);
integer Dy = (integer)llGetSubString(Data,8,9);
float XVal = Yr * YrDays + (Mn - 1) * MnDays + Dy * DyInc;
// We calculate the difference between those two dates to get the number of days.
integer DDiff = (integer)(XVal - uXVal);
// Here we check if the calculated age fits our requirements.
if (DDiff < 180) {
llSetText("Age Check Failed!\nYou are younger than 180 days!",<1,0,0>,1);
} else {
llSetText("Age Check Passed!",<1,1,1>,1);
}
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
04-21-2007 10:26
/54/25/178768/1.html
_____________________
i've got nothing. ;)