Jump to content

Trying to sell multiple items from a single thread


ChaosRaine
 Share

You are about to reply to a thread that has been inactive for 3812 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm trying to set up  a script so that it will detect which face is selected to pay and it will sell diffrent items at diffrent prices depending on which face is selected. I have a basic script to sell items, but I can't figure out how to get it to change depending on the side selected. I can post what I have if anybody wants to see it.

Link to comment
Share on other sites

Ok so far this is what I have ended up with. It still doesn't work it just sells the first object

integer price =10;
integer demo =0;
integer moneys =3; //price how much !!!!!!!!!!!!!!!!!!!
key target;
//key otherone="key---key----key---key";//Input others key here value
//integer qian=1; //If need to pay others, importation amount
string oname="little box";
string dname="big box";
string cname="extra"; //Merchandise name

default

{
state_entry()
{
integer face = llDetectedTouchFace(5);
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()
{
llSetPayPrice(price, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
;

}
money(key id, integer amount)
{
target=id;
llRequestAgentData( id, DATA_NAME );
if(amount != price)
{
llGiveMoney(id, amount);
llInstantMessage(id, "You paid "+(string)amount+", which is the wrong price, the price is: "+(string)price);
}
else
{

// llGiveMoney((key)otherone,qian);
llGiveInventory(target, oname);
// llDie(); // Delete object
}
}
on_rez(integer param)
{

llResetScript();
}
}
state sidetwo
{
state_entry()
{
integer face = llDetectedTouchFace(4);
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 cashtwo;
}
}

state cashtwo
{
state_entry()
{
llSetPayPrice(demo, [demo ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);

}
money(key id, integer amount)
{
target=id;
llRequestAgentData( id, DATA_NAME );
if(amount != demo)
{
llGiveMoney(id, amount);
llInstantMessage(id, "You paid "+(string)amount+", which is the wrong price, the price is: "+(string)dname);
}
else
{

// llGiveMoney((key)otherone,qian);
llGiveInventory(target, dname);
// llDie(); // Delete object
}
}
on_rez(integer param)
{

llResetScript();

}
}
state sidethree
{
state_entry()
{
integer face = llDetectedTouchFace(3);
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 cashthree;
}
}

state cashthree
{
state_entry()
{
llSetPayPrice(moneys, [moneys ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
money(key id, integer amount)
{
target=id;
llRequestAgentData( id, DATA_NAME );
if(amount != moneys)
{
llGiveMoney(id, amount);
llInstantMessage(id, "You paid "+(string)amount+", which is the wrong price, the price is: "+(string)cname);
}
else
{

// llGiveMoney((key)otherone,qian);
llGiveInventory(target, cname);
// llDie(); // Delete object
}
}
on_rez(integer param)
{

llResetScript();

}
}

Link to comment
Share on other sites

So far, that's mostly because there's no way to get from state default to any other state except state cash.  All of your other states are inaccessible. In addition, you have misunderstood the way llDetectedTouchFace() works.  It needs to be in a touch* event to have any effect at all, and even there you'll want to look for llDetectedTouchFace(0) anyway.  You want to know whether the result of that query is == 3 or 4 or 5

  • Like 1
Link to comment
Share on other sites

Well there are several problems in that, although it isn't easy to read!  (Click the icon above the post message box that looks like a clipboard with a 'C' on it - that lets you post formatted code).

The first thing that happens is the default state, state_entry() event-handler is run.  There you check llDetectedTouchFace(), which has no meaning there "For the touch category of events only.".  That is, you can't check which face has been touched until/unless a face has been touched!  Then again, you're storing the meaningless result (into integer Face) but not doing anything with it anyway.

You then ask for debit permission and go into state cash.  Ok, but the script has no way to reach the other states.

In state cash, state_entry() you "llSetPayPrice(price, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);" but price is 10, as defined in the first line of the script and never changed anywhere else.

Then, when the object gets paid you ask for the payor's name but don't do anything with that and either refund the money or give them that one thing.

Apart from the logic not working there is the problem that someone else might touch, or pay, the object while someone else is already carrying-out a transaction.

Odd as it may seem I'd recommend that you set your different prices into the llSetPayPrice() and just give them whichever object matches the amount they pay you.  Much easier that way.

  • Like 1
Link to comment
Share on other sites

some ideas...?

I'd post more, but SL wont let me open my scripts ryte now :P

this is just the basics of getting the face...

integer face;
integer price;
string item;
string name;
init()
{
     llSetClickAction(CLICK_ACTION_TOUCH);
      llSetText("", <0,1,0>,1.0);
      item = "";
      price = 0;
 llSetLinkPrimitiveParamsFast(LINK_THIS,
        [PRIM_GLOW, ALL_SIDES, 0.0]);
}
default
{
    state_entry()
    {
        init();
    }

    touch_start(integer total_number)
    {  name = llDetectedName(0);
       face = llDetectedTouchFace(0);

 llSetLinkPrimitiveParamsFast(LINK_THIS,
        [PRIM_GLOW, ALL_SIDES, 0.0]);
        llSetLinkPrimitiveParamsFast(LINK_THIS,
        [PRIM_GLOW, face, 0.1]);

       if(face == 0) { item = "something 0"; price = 10;}
       if(face == 1) { item = "something 1"; price = 11;}
       if(face == 2) { item = "something 2"; price = 12;}
       if(face == 3) { item = "something 3"; price = 13;}
       if(face == 4) { item = "something 4"; price = 14;}
       if(face == 5) { item = "something 5"; price = 15;}

       llSay(0,"Click again to buy this item");
       llSetText("ITEM: " + item + " Price: " + (string)price +
                 "\nIn USE by: " + name  , <0,1,0>,1.0);
       llSetClickAction(CLICK_ACTION_PAY);
    }
}

  After the Money event, reset the cllick action, and  do init();

:)

  • Like 1
Link to comment
Share on other sites


ChaosRaine wrote:

...it shows how new I am at scripting.

We all were at some time, keep trying.

There are several things to consider when scripting a multi-vendor.

  1. Someone may "touch" one option, change their mind and want to "touch" a different one - you don't want to force their second click to be a 'pay'.
  2. Someone may "touch" and not pay (or pay the incorrect amount and not re-pay the right amount) - you need to time-out waiting for them at some point to let someone else use the vendor.
  3. Between an original touch and final, successful, payment any number of other people may touch as well - they shouldn't go straight to 'pay' but neither should they change the original person's selection.  you need to decide what to do with them (either track multiple people at the same time or just tell them to try again later).
  4. The money() event is not raised for L$0 transactions - you need a different method for giving-away free items/demos.

The simplest solution, if you have 4 or fewer options, is to make sure your prices for each are all clearly displayed and then just have click-pay,  Let the customer decide which price they want to pay, check it matches one of the options and give them the appropriate item.

The drawback of this approach is that they have to select the correct pay option, but it means 1) they only have to click the vendor once, 2-3) your script handles everything in the money() event-handler, 4) if needed have a L$1 demo/freebie and immediately refund the money.

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3812 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...