Jump to content
Cielo Aulder

Get username from an object's owner

Recommended Posts

Hello, i'm not very good at this, but i wanna get the username of the owner of an object, so i made this:

 

key Owner;

default
{
 

    touch_start(integer total_number)
    {
              llSensor("", NULL_KEY,SCRIPTED , 3.0, PI);
    }
    
    sensor( integer detected )
    {
        while(detected--)
        {
            Owner=llGetOwnerKey(llDetectedKey(detected));
            llSay(0, Owner);
            llInstantMessage(llGetOwner(), "The owner is: "+llGetDisplayName(CarOwner)+" ("+llGetUsername(CarOwner)+")");
            return;

        }
    }
}

and what's killing me is that with some objects from certain owners it works just fine, and i get this:

[10:23] Object: 7d42438e-d9c3-4b12-a610-34dfa6f29448
[10:23] Object: The owner is:  Cielo Aulder (cielo.aulder)
 

but with others i get something like this:

[10:23] Object: 0c26902e-40c3-4fbe-98ef-3d9455292f10
[10:23] Object: The owner is:  ()

 

Somehow llGetDisplayName and llGetUsername is not working there... but the key on Owner is fine. And I don't understand why with certain people it works just fine..

I hope you can help me.

Thanks.

Share this post


Link to post
Share on other sites

A couple of issues.....

llGetDisplayName, llGetUsername, llKey2Name, and most similar functions will only work if the person you are asking about is in the same region at the moment.  Otherwise, you get diddly.

Some objects are group owned, so you won't get anything at all when you ask for the owner's name.

You can use llGetObjectDetails(UUID_of_object,[OBJECT_OWNER]) and compare it with OBJECT_GROUP.  If the two are the same, you won't get a name, so stop trying.  Then, use llRequestDisplayName or llRequestUsername to provoke a response in a dataserver event if the owner is an avatar.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Off the top of my head, I suspect the problem may be that llGetUsername() and llGetDisplayName() work only if the avatar whose uuid is supplied is on the region.

If you want to know the username or display name of someone who isn't on the region, you need llRequestUsername and llRequestDisplayName

http://wiki.secondlife.com/wiki/LlRequestUsername

http://wiki.secondlife.com/wiki/LlRequestDisplayName

which return the Username and DisplayName of the avatar in the dataserver server event.   You might want to refresh your memory on how the dataserver event works if you're not familiar with it -- in particular, functions that raise a dataserver event return a key, not the data you're expecting.   So you need a structure like this:

key kUsernameQuery;
key kDisplayNameQuery;
key kOwner;
key kToucher;
default
{
	state_entry()
	{
		
	}
	touch_start(integer total_number)
	{
		kToucher = llDetectedKey(0);
		kOwner = llGetOwner();
		kUsernameQuery = llRequestUsername(kOwner);//raise a dataserver event 
	}

	dataserver(key requested, string data)
	{
		if(requested == kUsernameQuery){//if it's a reply to the query about the owner's username
			llRegionSayTo(kToucher,0,"The owner's username is "+data);
			kDisplayNameQuery = llRequestDisplayName(kOwner);
		}
		else if (requested == kDisplayNameQuery){
			llRegionSayTo(kToucher,0,"The owner's display name is "+data);
		}
	}
}

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

The viewer URI namespace stuff can also very useful: http://wiki.secondlife.com/wiki/Viewer_URI_Name_Space. It too doesn't require the presence of the avatar in the region.

llInstantMessage(llGetOwner(), "The owner is secondlife:///app/agent/" + (string) CarOwner + "/completename.");

I generally like to use the "/inspect" variety as it makes the name a clickable link that opens a useful little info dialog with access to some of the more common avatar interactions.

llInstantMessage(llGetOwner(), "The owner is secondlife:///app/agent/" + (string) CarOwner + "/inspect.");

  • Like 2

Share this post


Link to post
Share on other sites

As people mentioned above.  The rule of thumb for any of the user name functions is: If the function has an immediate return the script function is only checking the user cache on the simulator.  (There are a number of ways a user can be added to the cache but the safest assumption is "the user is in the region, or has been in the region recently." A more indepth description can trigger mental breaks.)  The llRequestXYZ functions will do a call into the database if the information is not currently cached. This is more expensive and can take more time to execute (hence the need for the dataserver event.) however you will get a more authoritative answer.

  • Thanks 3

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.


×
×
  • Create New...