Jump to content

Payment Commission?


UbiquitousStudio
 Share

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

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

Recommended Posts

Hello, I am trying to make a payment, then split the amount paid by the percent and tell owner what was split. The issue is it is doing it backwards and telling me the amount that was not paid. Here is my script!

integer commissionpercent = 40;
integer newamount;

default
{
    state_entry()
    {
        llSetPayPrice(10, [10 , 25, 50, 100]);
    }

    touch_start(integer total_number)
    {
        llRequestPermissions(llDetectedKey(0), PERMISSION_DEBIT);
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_DEBIT)
        {
            state idle;
        }
    }
}

state idle
{
    state_entry()
    {
        llSetPayPrice(10, [10 , 25, 50, 100]);
    }
    
    money(key id, integer amount)
    {
        if(amount < 10)
        {
            llOwnerSay("Sorry, you must pay a minimum of L$10.");
            key id = llDetectedKey(0);
            llGiveMoney("da806bd6-c8ad-42b6-b78a-aeb154d6768c", amount);
            return;   
        }
        
        // Give myself the entire balance.
        llGiveMoney("da806bd6-c8ad-42b6-b78a-aeb154d6768c", amount);
        
        
    }// This is where my issue is, it is telling me the amount not paid.
        newamount = llRound(amount * (float)(commissionpercent/100));
        llOwnerSay((string)newamount);
}

Thanks for the help again! I am not very good at math and c++ so any help would be good.

Link to comment
Share on other sites

Try to avoid changing states when using permissions.  Strange things happen.  Just pretend the option to switch states in scripts isn't there.

Declare a variable TRUE/FALSE on whether you want it to do one thing or the other ~ then switch that variable.

 

Honestly. I haven't read your script in depth.  Just a bit of cursory advice based on the fact that I saw 2 states with perms changes and didn't want to read into it any more than that.

Link to comment
Share on other sites

The math is correct but it calculates the percentage paid as commission to someone else, what you probably want is the remainder that you keep for yourself.

If you substitute a number as the amount, say 40% of 50 which is 20 paid as commission.

 

newamount = 50 * (40/100)

newamount = 50* 0.4

newamount = 20

 

If you want the remainder:

 

 newamount = amount - (llRound(amount * (float)(commissionpercent/100)));

 

Link to comment
Share on other sites

This is not C++.  It's LSL.  That's not your problem, though.

A money event always gives the script's owner the entire amount that it receives.  No exceptions.  That means, first of all, that you never need to use llGiveMoney to send the money to yourself from the money event.  If you want to make a split payment vendor, you'll use llGiveMoney to send part of the money to someone else. 

Now, you have a couple of other odd things going on in your money event.  The UUID of the person who triggered the event is in the variable id, which was grabbed by the event in its opening line:

money(key id, integer amount)

so you already know it.  There's no point in trying to redefine it again with

key id = llDetectedKey(0);

And if you did want to do that for some obscure reason, you couldn't do it with llDetectedKey(0), which only works in touch*, collision*, and sensor events.  Then, you jump out of an if test with a return, which is bad form, likely to yield odd results, even if it works. The correct way is to follow the if with an else code block, but of course, there's no point in the llGiveMoney statement you wrote, as I already pointed out, so you ought to just forget anything after the if test that you wrote.

Finally, the lines that you closed your script with

       newamount = llRound(amount * (float)(commissionpercent/100));        llOwnerSay((string)newamount);

are outside of any event, so they will kick up a syntax error.  If you really want to add code to redistribute some of the money, you need to put those lines in the money event.

If you want to see how a spli payment might be written, compare yours to https://community.secondlife.com/t5/LSL-Library/Split-Payment-Vendor/m-p/722093

Link to comment
Share on other sites

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