Overview
I am a builder and scripter in Second Life. I make tutorial videos to teach how to build and script. The scripts below were written from scratch my YouTube videos.
Tip Jar
// Total tips
integer total_tips;
// Last tip
integer last_tip;
// Last tipper
string last_tipper;
// The seconds touch has been held
float touch_seconds;
default
{
state_entry()
{
// Erase hover text
llSetText("",<1.0,1.0,1.0>, 1.0);
// Set pay window buttons and custom pay
llSetPayPrice(175,[50, 100, 150, 200]);
}
// Money event
money(key payer, integer amount)
{
// Accumulate tips
total_tips += amount;
last_tip = amount;
// Last tipper's name
last_tipper = llGetDisplayName(payer);
// Set hover text with latest info
llSetText("Total Tips: L$"+(string)total_tips+
"\nLast Tipper: "+last_tipper+" L$"+(string)last_tip,<1.0,1.0,1.0>, 1.0);
}
touch_start(integer total_number)
{
// Store the current time in seconds that script has been running
touch_seconds = llGetTime();
}
touch_end(integer total_number)
{
// Check to see if time touch was held is longer than 1.0 seconds
if ((llGetTime()-touch_seconds) > 1.0)
{
// Clear all
llSetText("",<1.0,1.0,1.0>, 1.0);
total_tips = 0;
last_tip = 0;
last_tipper = "";
}
}
}
Radar HUD
// Stores 1 or 0 for our switch
integer switch;
// Interval of the timer, after initial turn-on
float interval = 2.0;
flip(integer status)
{
if (status == TRUE)
{
// On
llSetTimerEvent(0.2);
switch = TRUE;
llSetColor(<0.0,1.0,0.0>,4);
} else
{
// Off
llSetTimerEvent(0);
switch = FALSE;
llSetText("",<1.0,1.0,1.0>,1.0);
llSetColor(<1.0,0.0,0.0>,4);
}
}
default
{
state_entry()
{
// On
flip(TRUE);
}
attach(key avatar)
{
// If attach point is an avatar
if (avatar != NULL_KEY)
{
// On
flip(TRUE);
}
}
touch_start(integer total_number)
{
// Flip switch integer
switch = !switch;
// Flip switch
flip(switch);
}
touch_end(integer nothing_needed)
{
// Kills touch event so it doesn't
// go to another state, if we have one
}
sensor(integer number)
{
// A counter to loop through avatar data
integer counter;
// A list to store avatar info
list avatars;
// A string to store distance info
string distance;
// Our loop
for(counter = number - 1; counter > -1; counter --)
{
// Get distance
distance = (string)llVecDist(llGetPos(),
llDetectedPos(counter));
// Chop off extra decimal numbers
distance = llGetSubString(distance,0,
llSubStringIndex(distance,".")+1);
// Store our avatar data in a list
avatars += [llGetDisplayName(llDetectedKey(counter))+
" "+distance+"m"];
}
// Dump our list to hover text
llSetText(llDumpList2String(avatars,"\n"), <1.0,1.0,1.0>,1.0);
// Start timer at 2.0 seconds per tick
llSetTimerEvent(interval);
}
no_sensor()
{
// No avatars detected, nothing to display
llSetText("No avatars detected.",<1.0,1.0,1.0>,1.0);
// Start timer at 2.0 seconds per tick
llSetTimerEvent(interval);
}
timer()
{
// Turn timer off so we can do our work without overlap
llSetTimerEvent(0);
// Sense avatars within 96 meters, 360 degress
llSensor("","",AGENT,96.0,PI);
}
}