Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Trigger event every time agent moves

Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-28-2006 01:39
I wrote this script, and I want it to rez a "walkpad";(Flattened cylinder that dies after 2 seconds), and I need it to rez where my feet are. So it's constantly rezzing walkpads at the middle of my body for some reason. The one I've wrote so far rezzes them, but only at the center of my body.

CODE

float halfsize;
float fullsize;
vector pos;
key owner;
vector size;
float subsize;
float dec;
default
{
state_entry()
{
llListen(2,"",llGetOwner(),"");
}

listen(integer channel,string name, key id, string message)
{

if (message == "walkpads on")
{
llSetTimerEvent(.2);
llOwnerSay("Walkpads activated");
}
if (message == "walkpads off")
{
llOwnerSay("Walkpads deactivated");
llResetScript();
}
}
timer()
{
dec = .1;
size = llGetAgentSize(llDetectedKey(0));
owner = llGetOwner();
fullsize = (float)size.z;
pos = llGetPos();
halfsize = (float)fullsize / 2;
subsize = (float)halfsize - dec;
llRezObject("Walkpad", <pos.x,pos.y,pos.z - (float)subsize>,ZERO_VECTOR, ZERO_ROTATION,42);
}
}

Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
03-28-2006 03:09
You're resetting size based on the height of llDetectedKey(0), which doesn't exist since timer() doesn't generate it. So your size will always be 0. You want to get the height of llGetOwner().

I wouldn't recalculate all those size variables each time - the avatar's height is unlikely to change much and it'll slow things down. I'd just calculate everything that doesn't depend on the current position on state_entry or attach.

edit: also, you don't want to rez an object every 0.2 seconds either - keep track of the old position, and check it vs the new position, only rezzing an object when the new position is different to the old one by, say, a quarter the width of the platform. If you really wanted to be slick you could rez the platform in front of the av in the direction that it's moving so that the platforms didn't overlap.
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-28-2006 03:15
Actually, I fixed it to exactly what I wanted. Here is the finished version :D (the platforms die every 2 seconds.)
CODE

float halfsize;
float fullsize;
vector pos;
key owner;
vector size;
float subsize;
float dec;
default
{
state_entry()
{
llListen(2,"",llGetOwner(),"");
}

listen(integer channel,string name, key id, string message)
{

if (message == "pad on")
{
llSetTimerEvent(.01);
llOwnerSay("Walkpad feature activated." );
}
if (message == "pad off")
{
llOwnerSay("Walkpad feature deactivated.");
llResetScript();
}
}
timer()
{
dec = 1.2;
size = llGetAgentSize(llDetectedKey(0));
owner = llGetOwner();
fullsize = (float)size.z;
pos = llGetPos();
halfsize = (float)fullsize / 2;
subsize = (float)halfsize - dec;
llRezObject("Walkpad", <pos.x,pos.y,pos.z - (float)halfsize + subsize>,ZERO_VECTOR, ZERO_ROTATION,42);

}
}



This one works fine :D
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
03-28-2006 03:47
Well, yeah, it will - you've hardcoded the distance below the agent to rez the platform. You now don't need any of the av size stuff now - in fact, your timer could simply be

CODE
timer()
{
llRezObject("Walkpad", llGetPos() - <0.0, 0.0, 1.2>, ZERO_VECTOR, ZERO_ROTATION, 42);
}


I really wouldn't rez objects at maximum speed whether you need them or not though. It's terribly bad for sims.
Feynt Mistral
Registered User
Join date: 24 Sep 2005
Posts: 551
03-28-2006 12:39
For added efficiency you should add a script to your walkpad object that makes it temp on rez so it won't take up prims from the sim needlessly. You would also be wiser (depending on the size of your prim) making it spawn at a slower rate with your timer. Say, every 1 second (since they last 2 seconds). If it's a good sized prim, say 4m, a 1 second timer should meet your needs quite nicely.
_____________________
I dream of a better tomorrow in SL!
You should too. Visit, vote, voice opinions.
Support CSG! Tell LL how much it would mean to subtract one prim from another!
Prim Animation! Stop by and say something about it, show your support!
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-28-2006 13:43
Well it only leaves about 3 or 4 there at a time... They seem to disappear much faster then 2 seconds :D

Anyways, I had made this so I can walk around in the air; making me a personal bridge as I walk around, and this works perfectly. At 1 per second, It would not work unless I walked extrmely slowly.