Jump to content

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


istanbullet
 Share

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

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

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 comment
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 comment
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 comment
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 comment
Share on other sites

You are about to reply to a thread that has been inactive for 1110 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...