Don't click here unless you want to be banned.

LSL Wiki : LibraryInstantMessageAnyone

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl814.us.archive.org
Examples ScriptLibrary AnorcaCalamari BlindWanderer
This script can IM anyone in the W-HAT key database and on the grid you're on.
It can also give any inventory it has to people on command.


Channel Parameters Description Example
40 Avatar Name Gets the users key from W-Hat database /40 Anorca Calamari
50 Message Sends the message to the last avatar queried by the script /50 Hello Hello
60 Item Sends an item from the objects inventory to the last avatar queried by the script /60 InstantMessage


//Original Script Created by AnorcaCalamari
//Modified by BlindWanderer
//BlindWanderer added lag reducing features,Inventory check,non cap sensitive inventory and a few other things.
//Please do not sell this script except as a part of a larger creation. You may modify it.
//You can give this script away for free.
key requestid;
string resident;   
key target;
key owner;
string owner_name;

string InventoryType(string name, integer type)
{//finds an item in a case insensitive fashion of the given type and returns its true name.
    integer a = llGetInventoryType(name); 
    if(!~a)//a == INVENTORY_NONE
    {
        string b;
        a = llGetInventoryNumber(type);
        name = llToLower(name);
        while(a)
        {//(a = ~-a) is equivalent to --a, but runs faster.
            if(llToLower(b = llGetInventoryName(type, a = ~-a)) == name)
            {//we found a match ^^
                return b;
            }
        }
    }
    else if((a == type) ^ (!~type))//when type == INVENTORY_ALL, invert the result.
    {//the reason for this mess is that INVENTORY_NONE == INVENTORY_ALL
        return name;
    }
    return "";
}

default
{
    state_entry()
    {
        owner = llGetOwner();
        owner_name = llKey2Name(owner);//never changes.
        if(owner_name == "")
            requestid = llRequestAgentData(owner, DATA_NAME);//this should never need to be called but it's here just in case.
        llListen(40, "", owner, "");
        llListen(50, "", owner, "");
        llListen(60, "", owner, "");
    }

    listen(integer channel, string name, key id, string message)
    {
        if(channel == 40)
        {
            if((key)message)//check to see if message is a valid key.
            {//if it is, skip the lookup.
                target = message;
                resident = "";
            }
            else
            {//look up the name.
                list names = llList2List(llParseString2List(message, [" "], []), 0, 1);
                resident = llDumpList2String(names, " ");
                requestid = llHTTPRequest("http://w-hat.com/name2key?name=" + llDumpList2String(names, "+"), [HTTP_METHOD, "GET"], "");
                target = "";
            }
        }
        else if(target)
        {//make sure 'target' is a valid key.
            if(channel == 50)
            {
                llInstantMessage(target, owner_name + ": " + message);
            }
            else if(channel == 60)
            {
                name = InventoryType(message, INVENTORY_ALL);
                if(name)
                {//make sure name is not null.
                    llGiveInventory(target, name);
                }
                else
                {//if name is null, then the item could not be found.
                    llOwnerSay("Item \"" + message + "\" not found in inventory");
                }
            }
        }
        else
        {//since it wasn't channel 40, and target is invalid, it must be channel 50 or 60
            llOwnerSay("Invalid user, please lookup a user with \"/40 User Name\"");
        }
    }
    
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == requestid)
        {
            integer i = llSubStringIndex(body,resident);
            if ( i != -1 )
            {
                i += llStringLength(resident) + 1;//length of name plus a space.
                target = llGetSubString(body, i, i + 35);
                if(target)
                {//test the key to make sure it is valid
                    llOwnerSay("Headset set to: \"" + resident + "\" at key: " + (string)target);
                    return;
                }//if it is not valid fall through to the error message.
            }
            llSay(0,"No resident named \"" + resident + "\" found in the w-hat name2key database");
        }
        else
        {
            llSay(0, (string)status + " error");
        }
    }
    
    on_rez(integer rez_code)
    {
        if(llGetOwner() != owner)
        {
            llResetScript();
        }
    }
    
    dataserver(key id, string data)
    {
        if(id == requestid)
        {
            owner_name = data;
        }
    }
}

Original script by Anorca Calamari
Full names required.
Cap sensitive.
key requestid;
string resident;   

string target;
default
{
    state_entry()
    {
        llListen(40,"",llGetOwner(),"");
        llListen(50,"",llGetOwner(),"");
        llListen(60,"",llGetOwner(),"");
    }

    listen(integer channel,string name,key id,string message)
    {
        if(channel==40)
        {
            list names = llParseString2List(message,[" "],[]);
            resident = llDumpList2String(names," ");
            requestid = llHTTPRequest("http://w-hat.com/name2key?name="+llDumpList2String(names,"+"),[HTTP_METHOD,"GET"],"");
            target=message;
        }
        if(channel==50)
        {
            llInstantMessage((key)target,llKey2Name(llGetOwner())+":"+message);
        }
        if(channel==60)
        {
            llGiveInventory(target,message);
        }
    }
    
   http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == requestid)
        {
            integer i = llSubStringIndex(body,resident);
            if ( i != -1 )
            {
            string avatarkey=llGetSubString(body,i,i+llStringLength(resident)+36);
            llOwnerSay("Headset set to: "+target+" at key: "+avatarkey);
            avatarkey=llGetSubString(avatarkey,llStringLength(avatarkey) - 36,llStringLength(avatarkey));
target=avatarkey;
            
            }
            else
                llSay(0,"No resident named \""+resident+"\" found in the w-hat name2key database");
        } else
            llSay(0,(string)status+" error");
    }
}
Comments [Hide comments/form]
Thankyou whoever edited this page to have that table at the top.
-- AnorcaCalamari (2007-01-07 19:14:08)
You know your really not supposed to edit another persons script if you have a version you think is better then please create another page and put the modded version on it and the reason you think its better.
-- AnorcaCalamari (2007-01-07 20:37:33)
Thankyou BlindWanderer this page now has both versions.
-- AnorcaCalamari (2007-01-07 20:51:25)
It wasn't my intention to step on your toes, just make the script better. I was hoping you would consider these changes and review them and learn from them so that I wouldn't have to point them out. First is the white space, it's inconsistent, it looks bad (StyleGuide). Then there is the 'if' chain that wastes cpu time (using else-if's would fix that). Then the use of the target value during the request is strange; and then not checking to make sure it is a valid key before using, it's a logic hole. When the script is transfered the listens would still be keyed to the creator, which is a fixable flaw (see on_rez). Finally the use of multiple channels is considered a bad coding practice (causes lag, though I consider it forgivable, and changing it would require re-writing the interface).

When you post to the wiki you must understand that people will edit what you post. The main purpose of the Script Library is to provide a library of well written publicly available scripts that can be learned from. A flawed script is not well written by definition, nor should it be used to learn from. Not to mention it makes the wiki look bad.
-- BlindWanderer (2007-01-08 18:01:33)
Though I have not problem with the removal of the inventory case insensitivity; i threw that in as a bonus, makes the script easier to work with (and you should check to make sure the inventory exists before trying to give it out; the function to use to do that is llGetInventoryType, as it will not return an error message; the InventoryType function kills two birds with one stone in that regard, as it preforms the check and provides the case insensitivity handling).
-- BlindWanderer (2007-01-08 19:00:12)
thankyou i just wanted to mention i just wanted to let you know i didnt delete your code i just had put your modified version at bottom below original
thistime ill put my original version at bottom.
-- AnorcaCalamari (2007-01-08 19:58:56)
read my profile it says im a mediocre scripter.
-- AnorcaCalamari (2007-01-08 20:00:19)
i need to read up on how to look at a PIECE of a string.
-- AnorcaCalamari (2007-01-08 20:06:53)
ugg forgot == is a wiki command
-- BlindWanderer (2007-01-09 11:35:11)
okay thanks i looked up some stuff in the string section which i have used for my teleporter yay i think the teleporter works pretty well.
-- AnorcaCalamari (2007-01-09 15:01:36)
Attach a comment to this page: