Talk:LlParcelSay

From Second Life Wiki
Revision as of 10:27, 15 February 2015 by Strife Onizuka (talk | contribs) (suggested changes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

llParcelMessage

Here are some examples if you just want to send a message to all avatars on related parcels without a script delay:

llParcelMessage(string message)
{
    list avatars = llGetAgentList(AGENT_LIST_PARCEL_OWNER, []);
    integer count;

    for (count = 0; count < llGetListLength(avatars); count++)
    {
        llRegionSayTo(llList2String(avatars, count), 0, message);
    }
}

llParcelHeightMessage(integer min_height, integer max_height, string message)
{
    list avatars = llGetAgentList(AGENT_LIST_PARCEL_OWNER, []);
    vector avatar_pos;
    integer count;

    for (count = 0; count < llGetListLength(avatars); count++)
    {
        avatar_pos = llList2Vector(llGetObjectDetails(llList2String(avatars, count), [OBJECT_POS]), 0);

        if ((avatar_pos.z >= min_height) && (avatar_pos.z <= max_height))
        {
            llRegionSayTo(llList2String(avatars, count), 0, message);
        }
    }
}

default
{
    state_entry()
    {
        llParcelMessage("This message gets sent to all avatars on related parcels.");
        llParcelHeightMessage(400, 500, "This message only gets sent to avatars on related parcels who are at or above 400 meters, and also at or below 500 meters.");
    }
}

Sayrah Parx (talk) 08:21, 15 February 2015 (PST)

Your code is good and I like this idea. I would suggest a couple changes:
llParcelMessage(string message)
{
    list avatars = llGetAgentList(AGENT_LIST_PARCEL_OWNER, []);
    integer count = ~llGetListLength(avatars);

    while (++count)
    {
        llRegionSayTo(llList2Key(avatars, count), 0, message);
    }
}

llParcelHeightMessage(integer min_height, integer max_height, string message)
{
    list avatars = llGetAgentList(AGENT_LIST_PARCEL_OWNER, []);
    integer count = ~llGetListLength(avatars);

    while (++count)
    {
        key avatar_key = llList2Key(avatars, count);
        vector avatar_pos = llList2Vector(llGetObjectDetails(avatar_key, [OBJECT_POS]), 0);

        if ((avatar_pos.z >= min_height) && (avatar_pos.z <= max_height))
        {
            llRegionSayTo(avatar_key, 0, message);
        }
    }
}
Reasoning: The functions are expecting a key, but are getting passed a string, this will cause the compiler to insert a typecast. LSL does no loop hoisting. By pulling llGetListLength out of the conditional it speeds up the loop. To simplify the loop condition, I've changed it to use negative indexing. I've also cached the avatar_key, this also should speed up the loop since ALL list functions are pretty slow. -- Strife (talk|contribs) 09:27, 15 February 2015 (PST)