Jump to content

Limit the range of the ability to open an object's menu


Recommended Posts

Hello friends,

Think an object and you see a menu when you click on it (for example: "rezzer box menu" or "a vendor menu")

I want to do that an avatar can open the menu only When the avatar is in the range that I have set.

For example: If it clicks near 1 meter, the menu will open, if it clicks more than 1 meter away, the menu will not open and get a message like "Come Closer"

I am not a scripter. But i have an API add-on script for my object. maybe I can add a code into this script.

Can you help me please?

c56af4dc6af9e7ebe4e52617df223444.png.cd7a00997f3a1bc34e27b9c2dd0ced8e.png

Link to post
Share on other sites

Firstly, in order to get the functionality you want, you would probably need to make a slight adjustment to the main script; an addon script probably wouldn't be able to do much.

Secondly, your API script seems pretty useless. Unless you have some good documentation on what kinds of link_messages and chat commands the main script expects to send and receive, writing an addon script is almost impossible.

Now, if you had access to the main script, you would just have to add a line or two to the touch_start and or touch_end events :

touch_start(integer i)
{
    if(llVecMag(llDetectedPos(0)-llGetPos()) > 3.0) return;
    // the rest of the touch event code goes here.
}

where 3.0 in this example is the maximum distance (in meters) the object can be touched from.

  • Thanks 1
Link to post
Share on other sites

Instead of llVecMag, you can also use llVecDist, like below (http://wiki.secondlife.com/wiki/LlVecDist).  Do note that the distance from the prim is measured from the prim's center, so if your prim is large, then you will need to account for that.

integer IsWithinRange(float pfMaxRange, vector pvAvatarPos)
{
    return (llVecDist(llGetPos(), pvAvatarPos) <= pfMaxRange);
}

default
{
    touch_start(integer total_number)
    {
        if (IsWithinRange(2.0, llDetectedPos(0)))
        {
            //Do stuff
        }
        else
        {
            //Do other stuff
        }
    }
}

 

Edited by Bugs Larnia
Added link to Wiki
  • Thanks 1
Link to post
Share on other sites

both vecMag(a-b) and vecDist(a,b) are equivalent. because we're not doing this test repeatedly on a quick timer there's not much reason to use a more efficient version, but for refference, the most efficient version would be something like:

integer IsWithinRange(float pfMaxRange, vector pvAvatarPos)
{   vector diff = llGetPos() - pvAvatarPos;
    return diff*diff <= pfMaxRange*pfMaxRange);
}

as is mentioned at the bottom of that wiki page.

Edit: For maximum efficiency, you would drop the function call and do the test in-line.

Edited by Quistessa
  • Like 1
  • Thanks 1
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...