Jump to content
Sign in to follow this  
DarkEmperor13

Vending machine script(Part 2)

Recommended Posts

Ok so ever since I posted my last post with the same title as this one, I've gotten a bit better with understanding how to use the llSetPayPrice, llSetClickAction and Money scripts. However one thing I'm trying to do, for the life of me, is figuring out how to give a random item when you pay the vendor. Also before I forget, this is not the same vendor I used with the other post with the similar title. Instead I'm using a simple gacha. The code I wrote is:

integer price = 64;
 
default
{
    state_entry()
    {
        llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_DEBIT)
            state cash;
    }
}
 
state cash
{
    state_entry()
    {
        key id = llDetectedKey(0);
        llSetPayPrice(PAY_HIDE, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
    }
    money(key id, integer amount)
    {
        if(amount != price)
        {
            llGiveMoney(id, amount);
            llInstantMessage(id, "You don't have enough linden to make this purchase");
        }
        else
        {
            //insert your give code here.
            integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
            string itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
            llGiveInventory(id, itemName);
            llInstantMessage(id, "Thank you for your purchase!");
        }
    }
}

So what am I doing wrong?

Share this post


Link to post
Share on other sites

something kinda like....

 

string itemName = llGetInventoryName(INVENTORY_OBJECT,  llFloor( llFrand(  randomIndex ) )  );

 

Share this post


Link to post
Share on other sites
37 minutes ago, Xiija said:

string itemName = llGetInventoryName(INVENTORY_OBJECT,  llFloor( llFrand(  randomIndex ) )  );

You could just use 

string itemName = llGetInventoryName(INVENTORY_OBJECT,(integer)llFrand((float)randomIndex)));

since casting a float as an integer always rounds it down.

I'm casting randdomIndex as a float because I always cost things explicitly rather than hope the compiler will do it for me, but I don't know if it matters 

 

Share this post


Link to post
Share on other sites

it gave me a syntax error and text bar thingy moved to right before the last closed parentheses 

EDITED: Oh nvm u put an extra ")" at the end. Also I just realized that I posted the wrong script into the opening post. The actual codes is this(and I edited with the string code innula gave me):

integer price = 0;      // The price needed to purchase the item
 
default
{
    state_entry()
    {
        // Turn off pay options so no money can be received until we are ready
        llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        // Request Debit Permissions from the owner so refunds can be given
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
    on_rez(integer p)
    {
        llResetScript();                // Reset script on rezzing. Will thus register any change of owner.
    }
    money(key id, integer amount)        // Some money has been received and has gone to this object's owner
    {
        if (amount < price)
        {   // Customer has not paid enough
            llInstantMessage(id, "That's not enough money.");
            llGiveMoney(id, amount);   // Refund the money they paid
            return;
        }
        if (amount > price)
        {   // Customer paid too much. Refund the excess
            integer change = amount - price;
            llInstantMessage(id, "You paid more than L$" + (string)price
                + "  your change is L$" + (string)change );
            llGiveMoney(id, change);
        }
        // Customer has paid at least the right amount. Give them the item.
            integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
            string itemName = llGetInventoryName(INVENTORY_OBJECT,(integer)llFrand((float)randomIndex));  
            llGiveInventory(id, itemName);
            llInstantMessage(id, "Thank you for your purchase!");
    }
    run_time_permissions(integer perm)
    {
        // If Debit permissions are granted, set up the pay price for this single-price vendor
        if(perm & PERMISSION_DEBIT)
            llSetPayPrice(price, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
    }
}

Now I know I have the price as 0, but that's cause I wanted to test it and I have no lindens. But for some reason it still won't give me anythingplus the instantmessage doesn't show up. Is it because I have the price as 0? or is there something missing from the script I just posted?

 

Edited by DarkEmperor13

Share this post


Link to post
Share on other sites
32 minutes ago, DarkEmperor13 said:

Is it because I have the price as 0?

That's it.  You can't pay an object L$0 -- in fact, if you're using the official viewer, I think it's physically impossible (I can't see how to do it, since when I choose Pay from the right-click context menu, the Pay button on the paybox doesn't show if I enter 0, and llSetPayPrice won't display 0, either).

You could try testing on the beta grid, aditi, where you should have (I think)L$5000 available for testing purposes (can be used only on aditi, though -- you can't bring it back to the main grid). 

Share this post


Link to post
Share on other sites
13 minutes ago, Innula Zenovka said:

That's it.  You can't pay an object L$0 -- in fact, if you're using the official viewer, I think it's physically impossible (I can't see how to do it, since when I choose Pay from the right-click context menu, the Pay button on the paybox doesn't show if I enter 0, and llSetPayPrice won't display 0, either).

You could try testing on the beta grid, aditi, where you should have (I think)L$5000 available for testing purposes (can be used only on aditi, though -- you can't bring it back to the main grid). 

I've requested a "free" option for set pay price but it got declined, it's a right pain to require people to pay 1L and then send it straight back to them...

Share this post


Link to post
Share on other sites
On ‎22‎-‎4‎-‎2018 at 1:06 AM, Felis Catnap said:

I've requested a "free" option for set pay price but it got declined, it's a right pain to require people to pay 1L and then send it straight back to them...

Can't you just give out the item on touch instead of selling it for L$1 and then returning the L$1?

Share this post


Link to post
Share on other sites
1 hour ago, Christhiana said:

Can't you just give out the item on touch instead of selling it for L$1 and then returning the L$1?

I think the reason people like to sell items for L$1 and then return the L$ is that they then have a record of having given out the object, and to whom.   Obviously that's easy to do in a touch event, too, but it's more bother and, unless you're saving the record to an experience with a KVP key, you can store only a limited number of records without remembering to transfer the data elsewhere and then free up some space, otherwise there's a stack heap collision.

Personally I'm not too interested in knowing who I've given demo items/freebies to, but clearly some people do like to know.

Edited by Innula Zenovka

Share this post


Link to post
Share on other sites

That is a good point Innula. If it is only about the number of demos given out it's easy to store it in a local record. For avatar names and such an external database is ofcourse better. The downside to the L$1 price is that someone with no L$ in their account (yet) won't be able to purchase a demo. I can already hear people say "but if they have no money for the demo they certainly have no money to buy the product anyway". But when I started out I had a great time trying out demos just to see how things would look on my avi. When I started making some money in SL I did remember who's demos I tried and liked. It may have taken some time but in the end the free demos I bought did their job and I purchased some of the full products. 

Share this post


Link to post
Share on other sites

If a person just wants to track freebies from a vendor, they could have it send them a message letting them know who clicked on the vendor... Could get messy though.

Or, hey, it could just store the data the same way a visitor counter does, and then you could retrieve it later with a chat command or something... Iunno how you'd get it to tell you which item it gave to them, but it might be possible somehow...

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.

Sign in to follow this  

×
×
  • Create New...