Jump to content

Turret Script


DarkEmperor13
 Share

You are about to reply to a thread that has been inactive for 1425 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I need some help. I'm trying to make a turret that when senses a player, it points at them. I got the whole rotation thing down. 

default
{
    state_entry()
    {
        
        llSensorRepeat("", NULL_KEY, AGENT, 15.0, PI, 0.2);
        llSetLinkColor(LINK_THIS, <0,1,0>, ALL_SIDES);
       
    }

    sensor(integer num_detected)
        {
            llSetLinkColor(LINK_THIS, <1,0,0>, ALL_SIDES);
        }
    
    no_sensor()
    {
        llResetScript(); 
    }
}

See, I also have a part of the turret that changes between red and greem. Green = Anonymous/Passive & Red = Detected/Hostile. I got the turn red when detected player worked out, but I cant seem to make it go back to green when a player leaves its detection field.

Link to comment
Share on other sites

The logic as written will turn the object red if it senses any avatar within 15 meters, so you cannot test this up close because your own avatar will set it off.

If you go more than 15m from the object and there's nobody else around, it turns green again. I tested and that works, by the way.

Incidentally, running that sensor five times a second (the 0.2 argument) is way too fast to be a responsible use of sim resources. No turret has ever been worth that kind of lag effect on other scripts.

  • Like 2
Link to comment
Share on other sites

Inside the sensor event you will have 0 to num_found -1 detected agents, so step through the loop using an index >= 0 && < num_found, and ignore llDetectedKey(index) == owner. (Assume you have already set owner by llGetOwner to save repeated calls in the loop)

 

I'd post more but a cat is biting my leg to show he's starving.

Link to comment
Share on other sites

7 hours ago, DarkEmperor13 said:

well I was going to change it. I just wanted to make sure it works. Now is there a way to exclude the owner?

it is as Prof says. In the sensor event we check for owner and that the owner is the only avatar picked up by the sensor. Example:

sensor (integer num_detected)
{
   integer isOwnerOnly = (num_detected == 1) && (llDetectedKey(0) == llGetOwner());
   if (!isOwnerOnly)
   {
       llSetLinkColor(LINK_THIS, <1,0,0>, ALL_SIDES);
   }
}    

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1425 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...