Jump to content
Sign in to follow this  
Life Camino

How can I use a script to extract the region name from a landmark?

Recommended Posts

I'm trying to convert landmark information to landmark name, region name, local coordinates and I can get the landmark name and convert from global coordinates to local coordinates.  But, I can't seem to figure out how to extract the region name from the landmark.  Any suggestions?

Share this post


Link to post
Share on other sites

This should work correctly llRequestInventoryData() gives a vector to current region corner. You add 2, divide by 256 and you have the "grid coordinates" of the landmark which can be translated into the name through a HTTP Request:

 

key req;vector Absolute;default{    state_entry()    {        req= llRequestInventoryData(llGetInventoryName(INVENTORY_LANDMARK, 0));    }    dataserver(key id, string data)    {        if (id == req)        {            Absolute = llGetRegionCorner() + (vector)data;            vector grid = Absolute / 256.0;            req= llHTTPRequest("https://cap.secondlife.com/cap/0/b713fe80-283b-4585-af4d-a3b7d9a32492?"                                    + "var=name&grid_x=" + (string)llFloor(grid.x)                                     + "&grid_y=" + (string)llFloor(grid.y), [], "");        }    }    http_response(key id, integer status, list metadata, string body)    {        if (id == req)        {            if (status != 200)            {                llOwnerSay("Failure!");                return;            }            integer i = llSubStringIndex(body, "'");            body = llGetSubString(body, i + 1, -3);            llOwnerSay(llDumpList2String(, "/"));        }    }}

 

Share this post


Link to post
Share on other sites

Just a minor typo.

The output line should say

llOwnerSay(body);

not

 llOwnerSay(llDumpList2String(, "/"));

It's a nice script. It works for me.

If you want to make it slightly fancier, you might want to add a changed event so that the script responds when you drop a new landmark in it.  Create a new global string variable, gOldLM, and then modify the script with

    state_entry()    {        gOldLM = llGetInventoryName(INVENTORY_LANDMARK,0);        req= llRequestInventoryData(gOldLM);    }    changed(integer change)    {        if (change & CHANGED_INVENTORY)        {            llRemoveInventory(gOldLM);            gOldLM = llGetInventoryName(INVENTORY_LANDMARK,0);            req= llRequestInventoryData(gOldLM);        }    }  

 

 

Share this post


Link to post
Share on other sites

Yeah, it's been busted long enough that I forgot to keep looking.  I don't know when it came back up, but it's nice to have the API back again.  This is just the sort of thing it's good for.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...