Anyone want to double-check my "No-Copy item vendor script (NOT for gachas)" (Version 2!)

Clara D.

FOR PRESIDENT 2020!
Joined
Dec 24, 2018
Messages
2,240
Location
Phoenix, AZ, USA
SL Rez
2006
Joined SLU
Back in the day.
SLU Posts
100000000
Not posting this to the scripts bit for the forum as it involves debit and I'm not sure it's ready for prime time, I'd like someone to look it over and make sure I haven't missed anything, it's sort of critical with debit permissions that I get it right the first time.

Especially problematical was the fact that someone could pay it faster than LL's inventory system could get them the object, I tried to fix this by turning pay off briefly, then back on.

It's not for gachas, it just mindlessly dispenses whatever objects it has in order, then should shut down when out of things to give.

[edit to add]
Version 2.0
-Changed things for new mesh vendor
-Added error trap, apparently CHANGED_INVENTORY doesn't work worth a damn when I take no-copy items out manually >_<
-Error trap didn't cover someone overpaying with spam because of a delay between purchase and delivery, so disable/enable payment.

Code:
integer price = 10;
string vend_digits = "~VendorDigits2";
string offline_texture = "~Offline";
//==============================================================================
list offsets = [
    "0",<-0.375, 0.375, 0.0>, // 1
    "1",<-0.125, 0.375, 0.0>, // 3
    "2",< 0.125, 0.375, 0.0>, // 5
    "3",< 0.375, 0.375, 0.0>, // 7
    "4",<-0.375, 0.125, 0.0>, // 9
    "5",<-0.125, 0.125, 0.0>, //11
    "6",< 0.125, 0.125, 0.0>, //13
    "7",< 0.375, 0.125, 0.0>, //15
    "8",<-0.375,-0.125, 0.0>, //17
    "9",<-0.125,-0.125, 0.0>, //19
    "$",< 0.125,-0.125, 0.0>, //21
    "L",< 0.375,-0.125, 0.0>, //23
    "C",<-0.375,-0.375, 0.0>, //25
    "M",<-0.125,-0.375, 0.0>, //27
    "T",< 0.125,-0.375, 0.0>, //29
    " ",< 0.375,-0.375, 0.0>  //31
    ];
//=============================================================================
string give_sound = "8eae9c2b-3caa-477c-964d-c3752c23eddb";
string item_texture;
integer count = 29;
key owner;

set_display()
{
    string input;
    if(price > 999) input = "$"+(string)price;
    else if(price > 99) input = "$"+(string)price+"L";
    else if(price > 9) input = " $"+(string)price+"L";
    else input = "  $"+(string)price+"L";
    if(count > 9) input = input+(string)count+" ";
    else input = input+(string)count+"  ";
    integer C;
    list commands = [];
    for(C=0; C<8; ++C)
    {
        commands += [PRIM_LINK_TARGET, 2, PRIM_TEXTURE, C, vend_digits,
        <0.25,0.25,0.0>,llList2Vector(offsets,llListFindList(offsets,[llGetSubString(input,C,C)])+1),0];
    }
    llSetLinkPrimitiveParamsFast(0,commands);
}
default
{
    state_entry()
    {
        //Because SL is buggy af.
        llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        //Make the fan spin
        llSetTextureAnim(ANIM_ON | SMOOTH | ROTATE | LOOP, 0,1,1,0, TWO_PI, (llFrand(2.0)+1)*TWO_PI);
        //Set "not ready"
        llSetLinkAlpha(2,0.0,ALL_SIDES);
        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE,4,offline_texture,<1.0,1.0,0.0>,ZERO_VECTOR,0.0]);
        //Sanity checks
        if(llGetInventoryNumber(INVENTORY_SOUND) > 0) give_sound = llGetInventoryName(INVENTORY_SOUND,0);
        if(price > 9999 || price < 1)
        {
            llOwnerSay("ERROR: Price should be between 1 and 9999");
            return;
        }
        count = llGetInventoryNumber(INVENTORY_OBJECT);
        if(count > 99)
        {
            llOwnerSay("ERROR: Quantity over 99 not supported");
            return;        
        }
        integer texture_count = llGetInventoryNumber(INVENTORY_TEXTURE);
        if(texture_count < 3)
        {
            llOwnerSay("ERROR: Texture Missing!");
            return;
        }
        integer C;
        string test;
        for(C=0;C<texture_count;++C)
        {
            test = llGetInventoryName(INVENTORY_TEXTURE,C);
            if(test != vend_digits && test != offline_texture) item_texture = test;
        }
        //GTG, get permissions
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);              
    }
    changed(integer C)
    {
        if(C & (CHANGED_INVENTORY | CHANGED_OWNER)) llResetScript();
    }
    run_time_permissions(integer P)
    {
        if(P & PERMISSION_DEBIT)
        {
            if(count > 0) state running;
            else state offline;        
        }
    }    
}
state running
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE,4,item_texture,<1.0,1.0,1.0>,<0.0,0.0,0.0>,0.0]);
        llSetLinkAlpha(2,1.0,ALL_SIDES);
        set_display();
        llSetPayPrice(PAY_HIDE, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);        
    }
    money(key customer, integer amount)
    {
        //Even though we don't show the pay box, this is neccessary because exploits.
        if(amount != price)
        {
            llGiveMoney(customer, amount);
            llInstantMessage(customer, "Ya payed: "+(string)amount+", da prise is: "+(string)price);
        }
        //Because the changed event doesn't work well with no-copy inventory when manually removed.
        else if(llGetInventoryNumber(INVENTORY_OBJECT) < 1)
        {
            llGiveMoney(customer, amount);
            llInstantMessage(customer, "We dun hav no mor so givin refund. *sadfase*");
            state offline;            
        }
        else
        {
            llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
            llSetLinkAlpha(2,0.0,ALL_SIDES);
            llGiveInventory(customer, llGetInventoryName(INVENTORY_OBJECT,0));
            if(give_sound != "")llPlaySound(give_sound,0.5);
            count = llGetInventoryNumber(INVENTORY_OBJECT);
            if(count < 1) state offline;
            set_display();
            llSetLinkAlpha(2,1.0,ALL_SIDES);
            llSetPayPrice(PAY_HIDE, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]); 
        }
    }    
    changed(integer C)
    {
        if(C & CHANGED_OWNER) llResetScript();
        if(C & CHANGED_INVENTORY)
        {
            if(llGetInventoryNumber(INVENTORY_TEXTURE) < 3) llResetScript();
            count = llGetInventoryNumber(INVENTORY_OBJECT);
            if(count < 1) state offline;
            set_display();
        } 
    }     
}
state offline
{
    state_entry()
    {
        llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE,4,offline_texture,<1.0,1.0,0.0>,ZERO_VECTOR,0.0]);
        llSetLinkAlpha(2,0.0,ALL_SIDES);
    }
    changed(integer C)
    {
        if(C & CHANGED_OWNER) llResetScript();
        if(C & CHANGED_INVENTORY)
        {
            if(llGetInventoryNumber(INVENTORY_TEXTURE) < 3) llResetScript();
            count = llGetInventoryNumber(INVENTORY_OBJECT);
            if(count > 0) state running;
        }
        
    }    
}
 
Last edited: