Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple vehicle beacon... reduce vehicle litter!

Cubey Terra
Aircraft Builder
Join date: 6 Sep 2003
Posts: 1,725
01-03-2005 12:11
This simple beacon simply sends an IM at regular intervales to the owner. This reduces the number of stray vehicles around. It can be used as-is to "ping" the owner every x number of hours. Simply place it in your vehicle and set the change the "hours" variable to the number of hours between beacon pings.

It also responds to link messages with which you can set the beacon's interval, turn it on/off, and get a status message. I'll follow this script with an example of how to control the beacon from another script in the same object, such as the vehicle's main script.

Beacon script [edited to remove a couple of bugs.]
CODE

// Cubey's (very) simple vehicle beacon - Help prevent vehicle litter!
//
// January 03 2005 - Cubey Terra
// This script is free to copy, modify, and distribute. Share and enjoy!
//
// This script simply sends an IM at regular intervals to the owner.
// Any lost vehicles can be found. This reduces the number of stray
// vehicles that tend to litter the world.

// It can be used as-is to "ping" the owner every x number of hours.
// Simply place it in your vehicle and set the change the "hours" variable
// below to the number of hours between beacon pings.

// It also listens for link messages from other scripts in the object,
// with which you can turn the beacon on/off and set the beacon interval.
//
// To turn on the beacon, use this link message in another script:
// llMessageLinked(LINK_SET, 0, "beacon on", "");
// The beacon is on by default.
//
// Similarly, to turn off the beacon, use this link message in another script:
// llMessageLinked(LINK_SET, 0, "beacon off", "");
//
// To set the interval in hours, use this link message in another script:
// llMessageLinked(LINK_SET, numberOfHours, "beacon interval", "");
// where numberOfHours is an integer indicating the number of hours (of course) :).
//
// To get a status message, use this link message in another script:
// llMessageLinked(LINK_SET, numberOfHours, "beacon status", "");


integer hours = 24; // Number of hours between beacon IMs. Change this to suit your needs.


//No need to change anything below this line (unless you really want to, that is)
// ---------------------------------------------------------------------------

integer active = TRUE;
integer currentHours;

beaconStatus()
{
if (active)
{
llInstantMessage(llGetOwner(),"Beacon is ON. Message interval set to " + (string)hours + ". Next message in less than "+ (string)(hours - currentHours) + " hours. Hours elapsed since last message: " + (string)currentHours + ".");
}
else
{
llInstantMessage(llGetOwner(),"Beacon is OFF. Message interval set to " + (string)hours + ". You will not be messaged.");
}
}

init()
{
currentHours = 0;
if (active) {llSetTimerEvent(3600);}
}

default
{
state_entry()
{
init();
}

on_rez(integer num)
{
init();
}

link_message(integer sender_num, integer num, string str, key id)
{
string message = llToLower(str);

// Listening for message to turn on or off.
if (message == "beacon off")
{
active = FALSE;
llSetTimerEvent(0.0);
beaconStatus();
}
else if (message == "beacon on")
{
active = TRUE;
currentHours = 0;
llSetTimerEvent(3600); // 1 hour timer?
beaconStatus();
}

// To set the beacon interval from an external script, send the link message
// "beacon interval" and send the number of hours as an integer.
else if (message == "beacon interval")
{
hours = num;
currentHours = 0;
beaconStatus();
}

else if (message == "beacon status")
{
beaconStatus();
}
}

timer()
{
if (active)
{
currentHours += 1;
if (currentHours == hours)
{
vector pos = llGetPos();
llInstantMessage(llGetOwner(),"Locator beacon: Your vehicle is located at " + llGetRegionName() + "(" + (string)llRound(pos.x)+","+(string)llRound(pos.y)+") at an altitude of " + (string)llRound(pos.z) + " meters.");
currentHours = 0;
}
}
}
}



And now an example of how to control the beacon from another script in the same object:

CODE

// Cubey's beacon control example
// January 03 2005 - Cubey Terra
//
// This is an example of how to send link messages to the beacon script
// to turn it on/off, set the interval, and get status.


default
{
state_entry()
{
llListen(0, "", llGetOwner(), "");
}

touch_start(integer num)
{
llWhisper(0,"This is an example of a beacon controller script. It uses these chat commands:");
llWhisper(0,"BEACON ON");
llWhisper(0,"BEACON OFF");
llWhisper(0,"BEACON STATUS");
llWhisper(0,"BEACON INTERVAL n");
llWhisper(0,"... where n is the number of hours between beacon messages.");
}

listen(integer channel, string name, key id, string str)
{
string message = llToLower(str);

if (message == "beacon on")
{
llMessageLinked(LINK_SET, 0, "beacon on", "");
}
else if (message == "beacon off")
{
llMessageLinked(LINK_SET, 0, "beacon off", "");
}
else if (message == "beacon status")
{
llMessageLinked(LINK_SET, 0, "beacon status", "");
}
else if (llSubStringIndex(message, "beacon interval") == 0)
{
string beaconInterval = llGetSubString(message, 16, llStringLength(message) );
llMessageLinked(LINK_SET, (integer)beaconInterval, "beacon interval", "");
}
}
}

_____________________
C U B E Y · T E R R A
planes · helicopters · blimps · balloons · skydiving · submarines
Available at Abbotts Aerodrome and XstreetSL.com

Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
01-04-2005 02:29
I figure it should be possible to make the vehicles go back to some predetermined place by autopilot. I'll work on it if anyone feels interested enough.
Cubey Terra
Aircraft Builder
Join date: 6 Sep 2003
Posts: 1,725
Bug Hunters: Reward
01-04-2005 12:45
I'll give L$500 to the first person who can show me why my beacon waits twice as long between IMs as it supposed to. For example, I set it to 1 hour intervals and it IMs every 2 hours.

Prize will go to the first one to reply to this with a description of the problem and the corrected script. :)
_____________________
C U B E Y · T E R R A
planes · helicopters · blimps · balloons · skydiving · submarines
Available at Abbotts Aerodrome and XstreetSL.com

Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
01-04-2005 14:33
Wonderful idea :), one of my vehicles already does such. I might suggest that the beacon check online status before imming. Mine IMs every half hour and if it didn't check, it would quickly fill my email :/
_____________________
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
01-04-2005 22:49
From: Cubey Terra
I'll give L$500 to the first person who can show me why my beacon waits twice as long between IMs as it supposed to. For example, I set it to 1 hour intervals and it IMs every 2 hours.

Prize will go to the first one to reply to this with a description of the problem and the corrected script. :)


I doubt I'm the first. Hard to tell in the Scripting Library forum because it is moderated. :)

The bug is mis-diagnosed. It doesn't wait twice as long. It waits one hour more than it is supposed to.

Anyway, let's take a look at this code from the script:

CODE

timer()
{
if (active)
{
if (currentHours < hours)
{
currentHours += 1;
}
else
{
vector pos = llGetPos();
// IM owner
currentHours = 0;
}


currentHours is initialized to 0. The timer fires once an hour. Assume hours = 1, so it should IM every hour.

At the end of hour 1, the timer fires for the first time. currentHours = 0. hours = 1. Since 0 < 1, it increments currentHours and does *not* send an IM as it should.

At the end of hour 2, the timer fires for the second time. currentHours = 1. hours = 1. Since 1 is not < 1, it IMs the owner and resets currentHours to 0.

You could extrapolate this to any value for hours and it would always IM exactly one hour late.

SOLUTION:

CODE

timer()
{
if (active)
{
currentHours += 1;

if (currentHours == hours)
{
vector pos = llGetPos();
// IM owner
currentHours = 0;
}
_____________________
Prim Composer for 3dsMax
-- complete offline builder for prims and sculpties in 3ds Max
http://liferain.com/downloads/primcomposer/

Hierarchical Prim Archive (HPA)
-- HPA is is a fully-documented, platform-independent specification for storing and transferring builds between Second Life-compatible platforms and tools.
https://liferain.com/projects/hpa
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
01-05-2005 00:09
Cubey probably time dilation.

Why not just have the vehical drive itself off world with STATUS_RETURN_AT_EDGE set to true?
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Cubey Terra
Aircraft Builder
Join date: 6 Sep 2003
Posts: 1,725
01-05-2005 08:39
Shack wins the prize, although he missed another different bug. The timer isn't started in state_entry. I guess that's why I was getting odd results. :)

I'll post the corrected script. :)
_____________________
C U B E Y · T E R R A
planes · helicopters · blimps · balloons · skydiving · submarines
Available at Abbotts Aerodrome and XstreetSL.com

Jay Edelbrock
Registered User
Join date: 19 Feb 2005
Posts: 19
03-14-2005 07:10
Excelent script Cubey.

I'm tired of losing my vehicles and having to go back a week later and remove them from other people's land.

One question though(well, more of an idea):

You could write anoter little script that kills your ship if you say a phrase(ex: "kill ship";), that way, you dont have to go get it ^.^

You could also make it take your coordinates and have it fly to you. only problem I see with that is this: What if you(or your ship) is on an island?


One thing for certain: I'm using this. Oh, and do you mind if I put it on ships that I sell, as long as I give you credit for it/offer the script for free?
Cubey Terra
Aircraft Builder
Join date: 6 Sep 2003
Posts: 1,725
03-16-2005 11:46
From: Jay Edelbrock
You could write anoter little script that kills your ship if you say a phrase(ex: "kill ship";), that way, you dont have to go get it ^.^


You can easily mod this script to die instead of sending an IM. Simply replace the llIntantMessage line in the timer() with this:

llDie

After you rez the vehicle, it will wait for the timer interval, then die instead of messaging you. You may want to change the chat and IM messages accordingly, so that it's not so much a beacon as a kill script.

Don't use that mod in a no-copy vehicle though, or you'll never get it back. :)

From: someone
You could also make it take your coordinates and have it fly to you. only problem I see with that is this: What if you(or your ship) is on an island?


That would be very much more difficult, but not impossible. I wanted to keep this extremely simple.

From: someone
One thing for certain: I'm using this. Oh, and do you mind if I put it on ships that I sell, as long as I give you credit for it/offer the script for free?


Yes, it's free to use in anything you make/sell/give away. Just make sure you leave it copyable/modifyable and leave the header comments in.
_____________________
C U B E Y · T E R R A
planes · helicopters · blimps · balloons · skydiving · submarines
Available at Abbotts Aerodrome and XstreetSL.com