Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multi Object Rezzor Script Problems

PhoenixRene Ashbourne
Script Novice
Join date: 19 Feb 2008
Posts: 9
08-07-2008 15:29
I was hoping someone might be able to assist me with a scripting problem.

I found a script that I have placed a HUD. It was originally used to rezz fish, but I'm using it to rez pet demons. When I touch the HUD button, I can rez the objects placed within the HUD button. However, when I tried to delete the objects, they would not Die. I placed a ChatDie script in the rezzed object that would listen to anything say the correct command on the channel. This worked, but while I can now delete the rezzed objects, they always delete on their own even before I can hit the delete button on the HUD. If anyone can help me, I would really appreciate it.

Multi Object Rezzor Script


integer RADIUS_MAX = 9;
integer HEIGHT_MAX = 18;
float FREQ = 5; // how often to change target location

integer chanDlg;
integer chanFish = 10; // fish listen on this channel

integer numFish;
integer radius = 2; // radius around rezzer
integer height = 10; // max height of fish target -- meters relative to rezzer
integer lstn;

vector myPos;
vector target;


list fishTypes;

key owner;



vector chooseTarget()
{
myPos = llGetPos();
vector offset;
vector thisTarget;
offset.x = llFrand(2 * radius) - radius; // x/y offset can be negative
offset.y = llFrand(2 * radius) - radius;
offset.z = llFrand(height) + 0.5;
thisTarget = myPos + offset;
return thisTarget;
}


getFishTypes()
{
fishTypes = [];
integer i;
numFish = llGetInventoryNumber(INVENTORY_OBJECT);
for (i = 0; i < numFish; i++)
{
fishTypes += [llGetInventoryName(INVENTORY_OBJECT,i)];
}
}

init()
{
chanDlg = (integer)(llFrand(10000)+1000); // random chat channel to avoid interference
owner = llGetOwner();
if (lstn)
{
llListenRemove(lstn);
lstn = 0;
}
lstn = llListen(chanDlg,"", owner, "";);
myPos = llGetPos();
llOwnerSay("Click me to set the options.";);
}

menu()
{
string txt = "SET UP THE Demons!\n\tMax height: "+(string)height+"m above rezzer\n\tHorizontal radius: "+(string)radius+"m";

list buttons = ["Radius -","Height -","DELETE","Radius +", "Height +"] + fishTypes;

llDialog(owner,txt,buttons,chanDlg);
}

rezFish(string name)
{
llOwnerSay("Summoning "+name+".";);
llRezObject(name, chooseTarget(), ZERO_VECTOR, ZERO_ROTATION, 0);
llSetTimerEvent(FREQ);
}

killFish()
{
llOwnerSay("Dismissing all nearby Demons.";);
llSay(chanFish,"die";);
llSetTimerEvent(0);
}



default
{
state_entry()
{
init();
}

on_rez(integer num)
{
llResetScript();
}

touch_start(integer num)
{
getFishTypes();
integer i;
key agent = llDetectedKey(i);
if (agent == owner)
{
menu();
}
}

listen(integer channel, string name, key id, string message)
{
if (message == "DELETE";)
{
killFish();
}
else if (message == "Radius +";)
{
if (radius < RADIUS_MAX)
{
radius++;
}
else llOwnerSay("Radius is already at the maximum of "+(string)RADIUS_MAX+" meters.";);
menu();

}
else if (message == "Radius -";)
{
if (radius > 0)
{
radius--;
}
menu();
}
else if (message == "Height +";)
{
if (height < HEIGHT_MAX)
{
height++;
}
else llOwnerSay("Height is already at the maximum of "+(string)HEIGHT_MAX+" meters.";);
menu();
}
else if (message == "Height -";)
{
if (height > 0)
{
height--;
}
menu();
}
else if (llGetInventoryType(message) >= INVENTORY_OBJECT) // returns -1 if object of that name doesn't exist
{
rezFish(message);
menu();
}
}

timer()
{
integer i;
for (i = 0; i < numFish; i++)
{
vector t = chooseTarget();
//target,<fish name>,<x>,<y>,<z>
llSay(chanFish,"target,"+llList2String(fishTypes,i)+","+(string)t.x+","+(string)t.y+","+(string)t.z); // tell fish where to swarm
}

}


}



DIE Chat Script placed in Rezzed Object

default
{
state_entry()
{
llListen(10,"",NULL_KEY,"";);
}

listen(integer channel, string name, key id, string m)
{
if (m=="DELETE";);llDie();
}
}
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-07-2008 21:29
Hmm. This line COULD have something to do with it:

CODE

if (m=="DELETE");llDie();


Note that you have a semi-colon between the close parenthesis and the llDie() call. That means there is actually a do-nothing statement that is part of the 'if' construct, and your llDie() is executed unconditionally. It is equivalent to:

CODE

if (m == "DELETE")
{}

llDie();


So any time anything is said on channel 10 they will die. You might want to fix this to read:

CODE

if (m == "DELETE")
{
llDie();
}


I recommand ALWAYS using curly braces on conditionals, loops, etc.
PhoenixRene Ashbourne
Script Novice
Join date: 19 Feb 2008
Posts: 9
08-07-2008 22:56
I had to change the DELETE to die, but that solved my problem. Thank you so much. I really appreciate the help.