Jump to content

DISCOUNT Formula Script


Leander Tyles
 Share

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

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

Recommended Posts

Hi,


anybody help?


i cant figure out how to offer a 10% discount if a tenant rents 4 weeks in advance

i understand if i charge 20L pw and i recieved 80L.

if amount / rent_rate = 4 means they eligible for discount

but that formula dont work if they rent several months in advance.


anyway if a person pays a month in advance, or several months i want to return 10% of the amount they paid

--

hippotech got this in thier config

DISCOUNT PAY AT LEAST: 4 < handles any amount of weeks
DISCOUNT PERCENTAGE: 5%


i want my system to work the same way

 

keep in mind people have to pay the correct amount because they already refunded if wrong

 

 

money(key id, integer amount)
    {
        integer overPay = amount % RENT_RATE;
        if (paidLock)
        {
            llInstantMessage(id, "rental box is in use, try again in a minute or two");
            llGiveMoney(id, overPay); return;
        }

        integer weeks = amount / RENT_RATE; string msg = REFUND_MSG + (string)overPay;
        if (overPay && REFUND)
        {
            if (weeks) msg = "You have overpaid." + msg;
            else msg = "The minimum rent is L$" + (string)RENT_RATE + msg;
            llGiveMoney(id, overPay); llInstantMessage(id, msg); if (!weeks) return;
        }

        resetTimer(); paidName = llKey2Name(id); paidLock = TRUE;
        updateReqId = llHTTPRequest(UPDATE_URL +
                "?uuid=" + (string)id + "&name=" + llEscapeURL(llKey2Name(id)) +
                "&weeks=" + (string)weeks, [], "");
    }

 

Link to comment
Share on other sites

Well, no.  The condition you're looking for is if (Amount/RENT_RATE > 4) give discount.  It's a little hard to read through your coding, but I don't see why you have to deal with the discount business in the context of overpayment .  If you really want to deal with refunds, this should be enough....

if (weeks > 4){    msg = "You are entitled to a reduced rate." + msg;    llGiveMoney(id, Amount * 0.1);}

 Frankly, though, if I were doing this I wouldn't mess with refunds at all.  I'd just offer a menu that asks how many weeks the renter wants to pay for.  When the renter replies, offer a one-button PAY menu with the amount calculated at the appropriate rate.

Link to comment
Share on other sites

If I've properly understood you, I think you want to do something like this:

 

integer RENT_RATE = 120;//L$120 a weekinteger PAY_AT_LEAST = 4;float discount =5.0;//5%string strDiscount;default{	state_entry()	{		strDiscount=llGetSubString((string)discount,0,llSubStringIndex((string)discount,".")+2);		//express the discount as 2 decimal places	}	money(key giver, integer amount)	{		if (amount%RENT_RATE==0){//we've been paid a multiple of the rent			integer weeks = amount/RENT_RATE;			llRegionSayTo(giver,0, "You have paid for "+(string)weeks+" weeks' rent");			if (weeks >=PAY_AT_LEAST){				integer refund = (integer)((amount*discount)/100);				llRegionSayTo(giver,0,"Since you have paid for at least "+(string)PAY_AT_LEAST+" weeks, this entitles you to a discount of "+strDiscount+"%, which is L$"+(string)refund);				if(llGetPermissions()&PERMISSION_DEBIT){					llGiveMoney(giver,refund);				}			}		}	}}

 

Link to comment
Share on other sites

thanks guys one last question

how do i make it say 10% instead of 10.00

 

apart from changing it from a float or typing it into the message,

i dont realy understand the getsubstring line

 

        if (weeks >= PAY_AT_LEAST)
        {
        integer cashback = (integer)((amount*DISCOUNT)/100);
        string strDiscount=llGetSubString((string)DISCOUNT,0,llSubStringIndex((string)DISCOUNT,".")+2);   

        msg = "Paying for " + (string)PAY_AT_LEAST + " weeks or more at once means a discount of " +(string)strDiscount+  "%; refunding L$" + (string)cashback + ".";
        
        llSay(0,msg);
        llGiveMoney(id, cashback);  
        }

 

Paying for 4 weeks or more at once means a discount of 10.00%; refunding L$8.

Link to comment
Share on other sites

The llGetSubString line is so you don't end up saying "10.000000%", as will happen if you simply cast the float into a string.

string strDiscount=llGetSubString((string)DISCOUNT,0,llSubStringIndex((string)DISCOUNT,".")+2);   

Means something like, 

  • Cast DISCOUNT as a string
  • Find the first character (0).
  • Find the index of the first instance of a decimal point, using llSubStringIndex((string)DISCOUNT,".");
  • Add two to that, to give you two decimal places.

I did it that way so the formula would work for discounts of less than 10%.

If you simply want to say "5%" or "10%", the simplest way is probably just 

	llOwnerSay((string)((integer)discount)+"%");

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3982 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...