Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Please help a scripting noob.

danny2324 Fish
Registered User
Join date: 31 Jan 2006
Posts: 2
05-02-2006 05:58
Well this script refuzes to work right,If someones flying / driveing / running..it rezzs and stops them from hitting me,But if there walking...It dos nuthing at all!,Truly irrertatin,can someone please help with this?
_____________________________________________
default
{
state_entry()
{
llListen(0,"",llGetOwner(),"";);
}
listen(integer channel,string name,key id,string message)
{
if(message=="shield on";)
{
state on;
}
}
}
state on
{
state_entry()
{
llSensorRepeat("","",AGENT|ACTIVE|PASSIVE|SCRIPTED,40,TWO_PI,0.1);
llSetTimerEvent(0.01);
llListen(0,"",llGetOwner(),"";);
}
listen(integer channel,string name,key id,string message)
{
if(message=="shield off";)
{
state default;
}
}
sensor(integer i)
{
integer i;
for(i=0;i<15;i++)
{
if(llVecDist(llGetPos(),llDetectedPos(i) + llVecNorm(llDetectedVel(i))) < llVecDist(llGetPos(),llDetectedPos(i)) && llVecMag(llDetectedVel(i)) > 5.0 && llDetectedKey(i)!=llGetOwnerKey(llGetOwner()))
{
rotation rot = llGetRot();
rotation drot = llDetectedRot(i);
rotation between = llGetRot() * llRotBetween(<0.5,0,0> * llGetRot(), llDetectedPos(i) - llGetPos());
llRezObject("shield",llGetPos() + <0.5,0,0> * between,ZERO_VECTOR,between,0);
}
}
}
}

______________________________________________
PS i am on the teen grid.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
05-02-2006 06:46
Take 'SCRIPTED' out of your sensor flags. SCRIPTED doesn't quite behave as you'd expect, and prevents a sensor from detecting avatars.

Also, you might want to change your sensor() event to:

CODE
sensor(integer num)
{
vector mypos ;
vector targetpos ;
vector targetvel ;

integer i;
for(i=0;i<num;i++)
{
mypos = llGetPos() ;
targetpos = llDetectedPos(i) ;
targetvel = llDetectedVel(i) ;

if(llVecDist(mypos,targetpos + llVecNorm(targetvel)) < llVecDist(mypos,targetpos) && llVecMag(targetvel) > 5.0 && llDetectedKey(i)!=llGetOwnerKey(llGetOwner()))
{
rotation rot = llGetRot();
rotation between = rot * llRotBetween(<0.5,0,0> * rot, targetpos - mypos);
llRezObject("shield",mypos + <0.5,0,0> * between,ZERO_VECTOR,between,0);
}
}
}

This way it will only cycle through the number of objects detected, and not always the full 16 objects it can detect, and will probably be a little more efficient since it's not making so many calls to llGetPos() and llDetectedPos().
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"