Jump to content

Modify vendor script that allows to split earnings


NymphaeaMK
 Share

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

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

Recommended Posts

Hello,

I need your help. I've this script and I need to modify in order to allow it to split a 100% percentage to another avatar.
The point is that this script opens a menu window that makes it possible to buy the item as a gift,
for this reason I can't use a simple vendor script with the percentage split.

 

I copy the script here. Can anyone please modify it for me? I really can't make it work.
I'd like to reward the first one that will make it work, so please contact me inworld ( NymphaeaMK Resident )
or specify your name inworld and I'll be glad to offer you 50 L$

Thank you in advance for your help.

xxx Nym

 

//STRINGS
string sBUTTON_BUY = "BUY NOW";
string sBUTTON_GIFT = "SEND AS GIFT";
string sBUTTON_INFO = "INFORMATION";

string sMESSAGE_BUY = "Right click this vendor and click pay to buy this product.";
string sMESSAGE_BUY_SUCCESS = "Item successfully delivered!";
string sMESSAGE_GIFT = "Enter the full name of the recipient in local chat.";
string sMESSAGE_GIFT_SUCCESS = "Item successfully delivered to the recipient ";
string sMESSAGE_INFO = "Notecard is being sent.";
string sMESSAGE_BUY_FOR_GIFTED = "Avatar found. Right click this vendor and click pay to send this item now.";

string sDIALOGMESSAGE = "Please choose:";

string sERROR = "Name not found!"; //Name2key-error.

float fTIMEOUT_RESERVED = 60; //Seconds before time out.
float fTIMEOUT_NAME2KEY = 30; //Seconds before name2key times out.
string sTIMEOUT = "Timed out.";

vector vRESERVED_COLOR = <1.0, 1.0, 1.0>;
float fRESERVED_ALPHA = 1.0;
string sRESERVED = "Vendor is in use.";

integer iCHANNEL_NAME2KEY = PUBLIC_CHANNEL;
integer iCHANNEL_DIALOG = -4787644;

string sINVALID_AMOUNT = "Invalid amount!";

dialog(key kAvatar)
{
    llDialog(kAvatar, sDIALOGMESSAGE, [sBUTTON_BUY, sBUTTON_GIFT, sBUTTON_INFO], iCHANNEL_DIALOG);
}

string sPURCHASE_IM = " just bought ";
string sPURCHASE_IM2 = " at a price of ";
string sPURCHASE_IM3 = " L$ in region ";
ownerPurchaseIM(string sItemname, string sAvatarname)
{ //Send IM to owner.
    string sPrice = (string)((integer)llGetObjectDesc());
    string sSLURL = llGetRegionName() + getSLURLPos(llGetPos());
    llInstantMessage(llGetOwner(), sAvatarname + sPURCHASE_IM + sItemname + sPURCHASE_IM2 + sPrice + 
    sPURCHASE_IM3 + sSLURL);
}
string getSLURLPos(vector v)
{ //Returns SL-url-pos.
    return " (" + (string)((integer)(v.x)) + "," + (string)((integer)(v.y)) + "," + (string)((integer)(v.z)) + ")";
}

string sURL   = "http://w-hat.com/name2key"; //Name2key url.
key reqid;

integer iMAXLEN = 100;
string sPARAM = "?terse=1&name=";
httpdb_load(string sNAME)
{ //Perform name2key search.
  reqid = llHTTPRequest(sURL + sPARAM + llEscapeURL(sNAME), [HTTP_BODY_MAXLENGTH, iMAXLEN], "" );
}

key kUSER; //Globals.
string sGIFTEDNAME;
integer iREADY_FOR_PAYMENT = FALSE;
key kGIFTED;
integer iLISTEN;
default
{
    state_entry()
    { //Request debit-permission from owner.
        llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llSetTimerEvent(0.0); //Stop timer.
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }

    changed(integer change)
    { //Reset when changing owner.
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }

    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_DEBIT)
        { //Permissions granted, go to state perm.
            state perm;
        }
    }

    on_rez(integer start_param)
    {
        if (!(llGetPermissions() & PERMISSION_DEBIT) || llGetPermissionsKey() != llGetOwner())
        { //Permissions invalid.
            llResetScript();
        }
    }
}
state perm
{
    state_entry()
    { //Permissions given.
        llSetTimerEvent(0.0); //Stop timer.
        kUSER = NULL_KEY; //Reset key.
        sGIFTEDNAME = ""; //Reset name.
        llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llSetText("", vRESERVED_COLOR, fRESERVED_ALPHA);
    }

    touch_start(integer total_number)
    {
        kUSER = llDetectedKey(0);
        state inuse;
    }

    changed(integer change)
    { //Reset when changing owner.
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}
state inuse
{
    state_entry()
    { //Set up timeout for in-use-state.
        iREADY_FOR_PAYMENT = FALSE; //Reset ready-flag.
        kGIFTED = NULL_KEY; //Reset gifted-key.
        llSetPayPrice(PAY_HIDE, [(integer)llGetObjectDesc(), PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llSetTimerEvent(fTIMEOUT_RESERVED);
        llSetText(sRESERVED, vRESERVED_COLOR, fRESERVED_ALPHA);
        llListenRemove(iLISTEN);
        iLISTEN = llListen(iCHANNEL_DIALOG, "", kUSER, "");
        dialog(kUSER);
    }
    listen(integer channel, string name, key id, string message)
    {
        if (channel == iCHANNEL_DIALOG && id == kUSER)
        { //Correct channel and user.
            if (message == sBUTTON_BUY)
            { //Buy-option chosen.
                llSay(PUBLIC_CHANNEL, sMESSAGE_BUY);
            }
            else if (message == sBUTTON_GIFT)
            { //Gift-option chosen.
                state name2key;
            }
            else if (message == sBUTTON_INFO)
            { //Info-notecard-option chosen.
                if (llGetInventoryNumber(INVENTORY_NOTECARD) > 0)
                {
                    llGiveInventory(kUSER, llGetInventoryName(INVENTORY_NOTECARD, 0));
                    llSay(PUBLIC_CHANNEL, sMESSAGE_INFO);
                }
            }
        }
    }
    touch_start(integer num_detected)
    {
        if (llDetectedKey(0) != kUSER)
        { //Error message (non-user).
            llRegionSayTo(llDetectedKey(0), PUBLIC_CHANNEL, sRESERVED);
        }
        else
        { //Dialog.
            dialog(kUSER);
        }
    }
    money(key id, integer amount)
    {
        string sItem;
        if (amount != (integer)llGetObjectDesc())
        { //Invalid amount!
            llTransferLindenDollars(id, amount);
            llSay(PUBLIC_CHANNEL, sINVALID_AMOUNT);
            return;
        }
        else
        {
            if (llGetInventoryNumber(INVENTORY_OBJECT) > 0)
            { //Give item.
                sItem = llGetInventoryName(INVENTORY_OBJECT, 0);
                llGiveInventory(kUSER, sItem);
            }
            llSay(PUBLIC_CHANNEL, sMESSAGE_BUY_SUCCESS);
            ownerPurchaseIM(sItem, llKey2Name(kUSER));
            state perm; //Return to state perm.
        }
    }
    timer()
    { //Time's up for user. Go back to state perm.
        state perm;
    }
    changed(integer change)
    { //Reset when changing owner.
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}

state name2key
{
    state_entry()
    { //Setting up listener for name2key-query.
        iREADY_FOR_PAYMENT = FALSE; //Reset ready-flag.
        kGIFTED = NULL_KEY; //Reset gifted-key.
        llListen(iCHANNEL_NAME2KEY, "", kUSER, "");
        llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llSetTimerEvent(fTIMEOUT_NAME2KEY);
        llSay(PUBLIC_CHANNEL, sMESSAGE_GIFT);
    }
    listen(integer channel, string name, key id, string message)
    {
        if (channel == iCHANNEL_NAME2KEY && id == kUSER)
        { //User said name.
            sGIFTEDNAME = message;
            httpdb_load(sGIFTEDNAME);
        }
    }
    money(key id, integer amount)
    {
        string sItem;
        if (!iREADY_FOR_PAYMENT)
        { //Not ready for payment.
            return;
        }
        else
        {
            if (amount != (integer)llGetObjectDesc())
            { //Invalid amount!
                llTransferLindenDollars(id, amount);
                llSay(PUBLIC_CHANNEL, sINVALID_AMOUNT);
                return;
            }
            else
            {
                if (llGetInventoryNumber(INVENTORY_OBJECT) > 0)
                { //Give item.
                    sItem = llGetInventoryName(INVENTORY_OBJECT, 0);
                    llGiveInventory(kGIFTED, sItem);
                }
                llSay(PUBLIC_CHANNEL, sMESSAGE_GIFT_SUCCESS + sGIFTEDNAME);
                ownerPurchaseIM(sItem, llKey2Name(kUSER));
                state perm; //Return to state perm.
            }
        }
    }
    timer()
    { //Timeout of name2key (user did not enter name in chat, or name2key did not return a result).
        llSay(PUBLIC_CHANNEL, sTIMEOUT);
        state inuse;
    }
    changed(integer change)
    { //Reset when changing owner.
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    http_response(key id, integer status, list meta, string body)
    { //Response from Name2Key-request.
        if (id == reqid)
        {
            reqid = NULL_KEY;
            if((key)body == NULL_KEY)
            { //No key found.
                llSay(PUBLIC_CHANNEL, sERROR);
            }
            else
            { //Key found.
                llSetPayPrice(PAY_HIDE, [(integer)llGetObjectDesc(), PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                llSay(PUBLIC_CHANNEL, sMESSAGE_BUY_FOR_GIFTED);
                kGIFTED = (key)body;
                iREADY_FOR_PAYMENT = TRUE;
            }
        }
    }
}

Link to comment
Share on other sites

This isn't really the right place to offer to pay  people to fix scripts for you -- Inworld Employment would be better for that -- but it's a very simple fix.  The only complicating factor (which isn't particularly complicated) is that you're going to have to convert between floats ( numbers with decimal points) -- and integers (whole numbers) a bit, since you can't pay people fractions of L$ (I know you want to give 100%, but I'll demonstrate how to give any percentage.

First, the basic formula to calculate n% of x:

		//to answer question, what is fPercent of iAmount
		integer iAmount = 50;//amount we're working on.
		float fPercentage = 75.0;//the percentage to apply to it
		float result = ((float)iAmount * fPercentage)/100.0;
		llOwnerSay((string)((integer)result) +" is "+((string)((integer)fPercentage))+"% of "+(string)iAmount);

So, to apply this to your script, first add, right at the top of the script, before default,  a couple of global variables:

float fPercentage = 100.0; //you said you wanted to pay someone 100% of the price as a commission. If you wanted to pay only 75%, you would set it to 75.0
key kMyFriendsUUID = "some uuid";//fill in your friend's uuid here, so the script knows who to give the commssion to

By putting them up there, before default, you ensure you can refer to them anywhere in the script.

Then, find the money events  in both state inuse and state name2key, and make a small addition to both of them:

if (amount != (integer)llGetObjectDesc())
		{ //Invalid amount!
			llTransferLindenDollars(id, amount);
			llSay(PUBLIC_CHANNEL, sINVALID_AMOUNT);
			return;
		}
		else
		{

			if (llGetInventoryNumber(INVENTORY_OBJECT) > 0)
			{ //Give item.
				sItem = llGetInventoryName(INVENTORY_OBJECT, 0);
				llGiveInventory(kUSER, sItem);
				//**add this bit
				//given the item.  Now pay the commission
				integer iCommission = (integer)(((float)amount * fPercentage /100.0));
				llTransferLindenDollars(kMyFriendsUUID,iCommission);
				//**new bit ends
			}

That should do the trick. 

(no need to pay for advice in this forum).

Link to comment
Share on other sites

8 minutes ago, Innula Zenovka said:

(no need to pay for advice in this forum).

Certainly not for L$50.  Imagine the quality of service you would get in RL if you offered to pay professionals 20 cents to do anythingO.o

But Innula's right.  If you are not a scripter, the place to ask when you want someone else to do the work is the InWorld Employment forum.

Link to comment
Share on other sites

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