Tweenster/Auto Alpha

From CasperTech Wiki
Revision as of 13:54, 15 July 2018 by D1cd5b71-6209-4595-9bf0-771bf689ce00 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Auto Alpha is a system for creators to automatically set alphas on the Tweenster body when an item of clothing is worn.

With Tweenster v3, Auto Alpha is really simple to use!

  1. First, under "Alpha Cuts" on the Tweenster HUD, click "Clear All".
  2. Next, click the segments to set the alpha segments to suit your garment.
  3. On the Tweenster HUD, click "Options" and then choose "5" for "Output auto alpha code"
  4. In a few seconds, you will see some output like this:
    [06:40] >MM< Tweenster HUD v3: Your code is between the lines:
    [06:40] >MM< Tweenster HUD v3: -------------------------------
    [06:40] >MM< Tweenster HUD v3: SendAlphas(1, 33377316, 255, 0);
    [06:40] >MM< Tweenster HUD v3: SendAlphas(1, 256, 115, 140);
    [06:40] >MM< Tweenster HUD v3: SendAlphas(1, 33554432, 24, 231);
    [06:40] >MM< Tweenster HUD v3: SendAlphas(2, 8192, 25, 230);
    [06:40] >MM< Tweenster HUD v3: SendAlphas(2, 16384, 3, 252);
    [06:40] >MM< Tweenster HUD v3: -------------------------------
    
  5. Copy the part between the ---- lines, and remove the bit at the front, so it becomes something like:
    SendAlphas(1, 33377316, 255, 0);
    SendAlphas(1, 256, 115, 140);
    SendAlphas(1, 33554432, 24, 231);
    SendAlphas(2, 8192, 25, 230);
    SendAlphas(2, 16384, 3, 252);
    

    (Please note that this is only an example, your output will be different).

  6. Next, paste these lines between the "// ------ PASTE CODE BELOW ------" and "// ------ PASTE CODE ABOVE ------" lines in the script (it's around line 32), replacing what is there already.
  7. Hit save, and you're done! Just drop the script into your clothing. You may wish to set perms, but this is up to you.

Script

////////////////////////////////////////////////////////////////////////////////////////
//
//
//      Tweenster Alpha Control API V3
//
//      License: Creative Commons Attribution-ShareAlike 4.0 International
//
//      Copyright (2018) Meshmerized and CasperTech Ltd
//
//
////////////////////////////////////////////////////////////////////////////////////////


//=======================================================================
//
//  INSTRUCTIONS
//
//=======================================================================
//
//  The V3 Alpha API has been made much easier to use.
//
//  Simply set the alphas you want on Tweenster. Then, on the HUD,
//  go to OPTIONS and then 5 for "Output Auto Alpha Code".
//
//  Then, simply paste the code into the AutoAlpha function below
//  (between the { } ).
//
//  Example code is provided, just delete the stuff that's there already.

AutoAlpha()
{
    // ------ PASTE CODE BELOW ------
    SendAlphas(1, 33377316, 255, 0);
    SendAlphas(1, 256, 115, 140);
    SendAlphas(1, 33554432, 24, 231);
    SendAlphas(2, 8192, 25, 230);
    SendAlphas(2, 16384, 3, 252);
    // ------ PASTE CODE ABOVE ------
}   

//=======================================================================

//=======================================================================
//
//  Don't modify anything below this line unless you know what you're doing
//
//=======================================================================

integer on = FALSE;

list unsetCommands = [];
list setCommands = [];
string unsetCommand = "";
string setCommand = "";

string passCode = "";

SendAlphas(integer set, integer partMask, integer faceMask, integer alphaMask)
{
    setCommands += [llDumpList2String([set, partMask, faceMask, alphaMask], "\n")];
    unsetCommands += [llDumpList2String([set, partMask, faceMask, (~alphaMask) &~ 4294967040], "\n")];
}

SendCommand(string command)
{
    if (passCode == "")
    {
        llOwnerSay("AutoAlpha: Warning: Tried to send command without knowing the passcode..");
    }
    llRegionSayTo(llGetOwner(), 10101, "TWEENSTERV3\n3\n" + llGetObjectName()+"\n" + llSHA1String(passCode + (string)llGetKey()) + "\n" + command);
}

Apply(integer on)
{
    if (on)
    {
        unsetCommands = [];
        setCommands = [];
        AutoAlpha();
        setCommand = llDumpList2String(setCommands, "\n");
        unsetCommand = llDumpList2String(unsetCommands, "\n");
        llRegionSayTo(llGetOwner(), 10101, "TWEENSTERV3\n2");
    }   
    else
    { 
        SendCommand(unsetCommand);
    }
}

default
{
    state_entry()
    {    
        //The Tweenster body will talk back to us on port 10102, so this sets
        //up a listener
        llListen( 10102, "", "", "" );
    }
    attach(key id)
    {
        if (id != NULL_KEY)
        {
            // We wait 5 seconds before applying alphas to give other attachments time to unset theirs
            llSleep(5.0);
            Apply(TRUE); 
        }       
        else if (unsetCommand != "")
        {
            Apply(FALSE);
        }
    }
    listen(integer channel, string name, key id, string message)
    {
        //IMPORTANT : Always check that the message has come from the correct owner
        if (channel == 10102 && llGetOwnerKey(id) == llGetOwner())
        {
            list message_list = llParseStringKeepNulls(message, ["\n"], []);
            if (llList2String(message_list,0)!="TWEENSTERV3") return;
            
            integer cmd = llList2Integer(message_list,1);

            if (cmd == 1)
            {
                list masks = llParseStringKeepNulls(llList2String(message_list,2), ["|"], []);
            
                // These are no longer used by the Auto Alpha system.
                // However, they are available to you to use if you wish.
            }
            else if (cmd == 2)
            {
                passCode = llList2String(message_list, 2);
                SendCommand(setCommand);
            }
            if (cmd == 3)
            {
                //Alphas have been set successfully        
            }
        }
    }
}