Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Earthquake script - need help

Stephen Delcon
Registered User
Join date: 16 Feb 2007
Posts: 7
02-23-2007 02:20
I'm trying to script an earthquake, so when someone say "earthquake", the prims the script are attach to, become physical and un-linked, thus falling to the ground.

so far, I have this: (sorry for not making a code section in the post, but have NO idea of how to do that)
-------------------------------------------
default
{
on_rez(integer total_number)
{
state new;
}
}

state new
{
state_entry()
{
llSay(0,"let it FALL!!!";);
llListen(0,"",NULL_KEY, "";);
}

listen(integer channel, string name, key id, string message)
{
if(message=="earthquake";)
{
llSetStatus (STATUS_PHYSICS, TRUE);
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
run_time_permissions(integer perm)
{
if(PERMISSION_CHANGE_LINKS & perm) //should "perm" be "perm" or "128"?
{
llBreakLink( -4 );
}
}
state default;
}
else
{
state default;
}
}
}
------------------------------------
when I try to compile, the editor tell me there is an error at the "run_time_permissions" line, both with "perm" set to "perm" and to "128"...
that is the first problem, as I can't figure out what the error is.
The second problem, is that the object is not ment to be asking permission before activating the earthqake, so is there anyway to give it permission automatically?
Hope you can help, couse I'm pretty stuck!
-Stephen Delcon
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-23-2007 03:10
Firstly, to post code correctly use the PHP tags i.e. [ PHP ] and [ /PHP ] but without the spaces.

Your code is a bit muddled, You seem to have a few extra braces here and there.
You dont really need multiple states for this script so I suggest you put it all in state default.

Having an open ended listen on channel zero is a BAD idea, its much better handled on a different channel just so you dont have to process every piece of speech in a 100m radius.

You cannot have the run_time_permissions event handler inside the listen event handler. You fire of the request and then just wait for the reply. The permissions are probably best requested in state-entry and the unlink moved to the listen.

Not sure why you have -4 as the parameter to llBreakLink?, this should be the link number of the prim being unlinked which will always be positive. You probably want llBreakAllLinks to unlink the entire object



below is a Newgy-ised version, its untested.

CODE

default
{
state_entry()
{
llOwnerSay("let it FALL!!!");
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
// You really shouldnt do this!!!!!
// Alway try to minimise the amount of listen traffic.
// This will hear everything said by everyone within 20m (or 100m if shouting)
// This is quite a lot of processing overhead on the server.
llListen(0,"",NULL_KEY, "");
}

listen(integer channel, string name, key id, string message)
{
if("earthquake" == message)
{
llSetStatus (STATUS_PHYSICS, TRUE);
llBreakAllLinks();
}
}

run_time_permissions(integer perm)
{
if(PERMISSION_CHANGE_LINKS & perm)
{
llOwnerSay("Rock n Roll");
}
}
}


You may also need to apply an impulse to the object to start things falling
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Funny idea
02-23-2007 08:44
this could be cool.

The objects should also record their exact position before the Earthquake, so that aftwards they can go back where they started.
Stephen Delcon
Registered User
Join date: 16 Feb 2007
Posts: 7
thx
02-23-2007 08:59
Thanks a lot, newgate!
worked really well!
but was wondering, if there is a way, to avoid me granting permission each time?
want to build a building, having an object say "earthquake" on another channel, whatch the building fall, and then when it is over, I'll let the building delete itself, and have the object saying earthquake, to rez a new one... but I don't want to have to give permission every time, so is there a way to get past this?
thx for the help so far :)
oh, and I don't need the impulse to make it fall, gravity takes care of that :)
-Stephen Delcon

Edit:
I solved the problem, thanks a lot for the help! :)