Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Temp Prim Rezzer

Eata Kitty
Registered User
Join date: 21 Jan 2005
Posts: 387
08-02-2006 02:55
This is my version of those temporary rezzers that some jokers charge comedy prices for. I don't personally use one so I'm not sure if it's totally bug free and I didn't spend too long working on it so there's probably some improvements to be made.

Three scripts in the main object, one script for all objects to be rezzed.

Main object:
Dialog
CODE
integer CHANNEL;
// What we use here is a dynamic menu, this is a list that we define before
// calling the dialog. It allows us to have changing buttons by using
// global variables.
list dynMenu = [];

// Variables for dynamic menu buttons
string power = "Turn On";
string avSensor = "Sensor On";

default
{
state_entry()
{
CHANNEL = (integer)llFrand(2000000000.0);
llListen(CHANNEL, "", NULL_KEY, "");
}

touch_start(integer total_number)
{
// Build the dynamic menu before we use it as a dialog
list dynMenu = ["Reset", avSensor, power];
if (llDetectedKey(0) == llGetOwner())
llDialog(llDetectedKey(0), "What do you want to do?", dynMenu, CHANNEL);
}

listen(integer channel, string name, key id, string message)
{
llOwnerSay("You have selected: '" + message + "'.");
if (message == "Reset")
{
// Reset
llMessageLinked(LINK_THIS, 1000, "", NULL_KEY);
llMessageLinked(LINK_THIS, 1500, "", NULL_KEY);
power = "Turn On";
avSensor = "Sensor On";
}
else if (message == "Turn On")
{
// Go online
llMessageLinked(LINK_THIS, 1200, "", NULL_KEY);
power = "Turn Off";
}
else if (message == "Turn Off")
{
// Go offline
llMessageLinked(LINK_THIS, 1300, "", NULL_KEY);
power = "Turn On";
}
else if (message == "Sensor On")
{
// Start the sensor mode
llMessageLinked(LINK_THIS, 1400, "", NULL_KEY);
avSensor = "Sensor Off";
}
else if (message == "Sensor Off")
{
// Stop the sensor mode
llMessageLinked(LINK_THIS, 1500, "", NULL_KEY);
avSensor = "Sensor On";
}
}

on_rez(integer start_param)
{
llResetScript();
}

changed(integer change)
{
if (change & CHANGED_OWNER)
{
llResetScript();
}
}
}


Main
CODE

// Empty variables that will store set position/rotation
// DON'T CHANGE THESE
vector rezPosition = <0,0,0>;
rotation rezRotation = <0,0,0,0>;
// Inter-object commands
string commandDerez = "derez";
// Chat channel
integer commChannel;
// Rezzed object key
key childKey = NULL_KEY;
// How often our sensor checks, smaller is more responsive but more demanding
float sensorTime = 0.5;
// Tick to avoid getting pos too often
integer tick;
// avSensor is running
integer avSensor = FALSE;

// InventoryCheck
// Checks the status of our inventory
integer InventoryCheck()
{
// Check if we have too many objects
if (llGetInventoryNumber(INVENTORY_OBJECT) > 1)
{
llOwnerSay("ERROR - Too many objects! This rezzer only takes a single object");
return 1;
}
// No objects
else if (llGetInventoryNumber(INVENTORY_OBJECT) == 0)
{
llOwnerSay("ERROR - No objects in inventory!");
return 1;
}
// Inventory must be copy
if (llGetInventoryPermMask(llGetInventoryName(INVENTORY_OBJECT, 0), MASK_OWNER) & PERM_COPY)
return 0;
else
{
llOwnerSay("ERROR - Object does not have copy permissions");
return 1;
}
}

rez()
{
// Check if we have a rez position set, don't want to rez at 0,0,0
if (rezPosition == <0,0,0>)
llRezObject(llGetInventoryName(INVENTORY_OBJECT, 0), llGetPos(), ZERO_VECTOR, rezRotation, commChannel);
else
llRezObject(llGetInventoryName(INVENTORY_OBJECT, 0), rezPosition, ZERO_VECTOR, rezRotation, commChannel);
}

default
{
state_entry()
{
llSetAlpha(1.0, ALL_SIDES);
childKey = NULL_KEY;
}

changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
if (!InventoryCheck())
llOwnerSay("Ready to run");
}
if (change & CHANGED_OWNER)
{
llOwnerSay("New owner, resetting.");
llOwnerSay("To use me put a 0 Prim Object script inside the object you want to be rezzed then put it in my inventory and turn me on. You can fine tune the rez position/rotation through the Set P/R button (10M max distance).");
llResetScript();
}
}

link_message(integer sender, integer num, string message, key id)
{
// Turn on message
if (num == 1200)
{
if (!InventoryCheck())
state running;
}
// avSensor is running
else if (num == 1400)
{
avSensor = TRUE;
}
// avSensor is disabled
else if (num == 1500)
{
avSensor = FALSE;
}
else
{
llOwnerSay("Error - Rezzer not running");
}
}
}

state running
{
state_entry()
{
llOwnerSay("Running.");
childKey = NULL_KEY;
llSetTimerEvent(0.0);
llSetAlpha(0.0, ALL_SIDES);
// Random comm channel
commChannel = (integer)llFrand(2000000000.0);
// Create object
if (!avSensor)
rez();
}

object_rez(key child)
{
// Very important, we use this to sense our child
childKey = child;
llSleep(2);
llSetTimerEvent(sensorTime);
}

timer()
{
llSensor("", childKey, SCRIPTED, 10, PI);
}

sensor(integer num_detected)
{
if (tick >= 5)
{
tick = 0;
rezPosition = llDetectedPos(0);
rezRotation = llDetectedRot(0);
}
else
tick++;
}

no_sensor()
{
childKey = NULL_KEY;
rez();
}

on_rez(integer param)
{
// Move back to default, keep object info
state default;
}

changed(integer change)
{
// If out inventory changes
if (change & CHANGED_INVENTORY)
{
// This calls our inventory check function, if there is an inventory
// problem it returns a 1 which will causes us to return to default
if (InventoryCheck())
state default;
}
}

link_message(integer sender, integer num, string message, key id)
{
// Reset
if (num == 1000)
{
llOwnerSay("Resetting - Object info cleared");
llSay(commChannel, commandDerez);
llResetScript();
}
// Turn on message
else if (num == 1200)
{
llOwnerSay("Rezzer already running... resynching with dialog");
// Inform user, we don't really need to do anything as dialog will now be in synch
}
// Turn off message
else if (num == 1300)
{
llOwnerSay("Rezzer turning off...");
llSay(commChannel, commandDerez);
llMessageLinked(LINK_THIS, 1500, "", NULL_KEY);
state default;
}
// avSensor is running
else if (num == 1400)
{
avSensor = TRUE;
}
// avSensor is disabled
else if (num == 1500)
{
avSensor = FALSE;
}
// avSensor detected an av
else if (num == 2000)
{
if (childKey == NULL_KEY)
rez();
}
// avSensor detects no av
else if (num == 2100)
{
llSetTimerEvent(0.0);
llSay(commChannel, commandDerez);
childKey = NULL_KEY;
}
}
}


sensor
CODE

// Is the sensor enabled
integer active = FALSE;
// How often sensor checks, longer uses less resources but means slower reaction
integer sensorPeriod = 10;
// Distance in M the sensor will find avs
integer sensorDist = 20;
// Sensor detected an av on last run if true
integer avDetected = FALSE;

default
{
link_message(integer sender, integer num, string message, key id)
{
// Sensor on message
if (num == 1400)
{
avDetected = FALSE;
llSensorRepeat("", NULL_KEY, AGENT, sensorDist, PI, sensorPeriod);
}
// Sensor off message
else if (num == 1500)
{
avDetected = FALSE;
llSensorRemove();
}
}

sensor(integer total_number)
{
// Only do something if this is the first detection of an av
if (!avDetected)
{
// We detected something, tell Main to rez
llMessageLinked(LINK_THIS, 2000, "", NULL_KEY);
avDetected = TRUE;
}
}

no_sensor()
{
// Only do something if we had detected an av last sensor
if (avDetected)
{
// No avs, disable rezzing
llMessageLinked(LINK_THIS, 2100, "", NULL_KEY);
avDetected = FALSE;
}
}

changed(integer change)
{
if (change & CHANGED_OWNER)
{
llResetScript();
}
}
}


Script for rezzed objects:
CODE

// Chat channel
integer commChannel;

default
{
state_entry()
{
// Makes the object temporary so the whole 0 prim part works
llSetPrimitiveParams([PRIM_TEMP_ON_REZ, TRUE]);
}

on_rez(integer param)
{
if (!param)
// If not rezzed by the rezzer this stops temporary so we can edit it
llSetPrimitiveParams([PRIM_TEMP_ON_REZ, FALSE]);
else
{
// Chat channel to use, passed to us as a rez parameter
commChannel = param;
llListen(commChannel, "", NULL_KEY, "");
}
}

listen(integer channel, string name, key id, string message)
{
// Security - check the object belongs to our owner
if (llGetOwnerKey(id) != llGetOwner())
return;
if (message == "derez")
llDie();
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Ah, Crap.
08-02-2006 08:05
Double posted. going to get it deleted. Please use /54/b2/126351/1.html to discuss this script.
_____________________
i've got nothing. ;)