ResellModule
De DigiWiki.
This is a resell module that allows a buyer to resell the same product and get a share depending on the number sold by that reseller.
// Resell module // (c)2007 Flennan Roffo - Logic Scripted Products and Product Services // END USER LICENCE // Permission is granted to use the script and to make changes, provided // the script is not sold for profit, and the original copy right is // contained in the script or derivate thereof. // // DESCRIPTION // Implementation of "BUYING WITH RESELL OPTION". // Put items for sale that the next owner can resell for the same price // and with a share for the next owner that depends on the number sold. // USAGE: // To activate reselling, grant permission debit. // // To deactivate reselling, issue: // /9 STOP RESELLING // // To (re)enable reselling, issue: // /9 START RESELLING // INSTALLATION & CONFIGURATION: // To put an item as resell item in an item sold to someone, do the following: // Adjust the pay price and pay_share list. // Pay share is a list of values used for each subsequent resell. // That value is the amount that can be kept by the reseller (owner of the item) // The pay_price - share is what the creator gets paied. // // For recursive use, place in the resell_item a copy of the original item and this script, // and repeat that for each next resell level. // REMARKS // For practical use you might want to add a Float text indicating the item name and price // when in state reselling (and reset that in the state not_reselling), and enhance it with // a notecard giver to potential buyers. ///////// EDITABLE VARIABLES \\\\\\\\\\\\\ integer pay_price=100; /////////// EDIT \\\\\\\\\\\\\\\\ list pay_share=[10,15,25,30,35,50]; /////////// EDIT \\\\\\\\\\\\\\\\ string resell_item="(item name of resell item)"; /////////// EDIT \\\\\\\\\\\\\\\\ ///// NON EDITABLE VARIABLES \\\\\\\\\\\\\\ integer num_shares; key creator; key reqNameCreator=NULL_KEY; key reqNameOwner=NULL_KEY; string creator_name=""; string owner_name=""; integer num_sold=0; integer perm_debit=FALSE; integer already_running=FALSE; /////////////////////////////////////////// default //////////////////////////////////////////////// default { /////////////////////////////////// state_entry() ////////////////////////////////////// state_entry() { if (!already_running) { num_shares=llGetListLength(pay_share); if (num_shares == 0) { llOwnerSay("pay_share prices are not filled. Contact creator."); state not_reselling; } integer i; for (i = 0; i < num_shares; ++i) { if (llList2Integer(pay_share,i) >= pay_price) { llOwnerSay("pay_share prices are not valid. Contact creator."); state not_reselling; } } creator=llGetCreator(); reqNameCreator=llRequestAgentData(llGetCreator(),DATA_NAME); reqNameOwner=llRequestAgentData(llGetOwner(),DATA_NAME); } if (!perm_debit) { llOwnerSay("Resell running. Give permission DEBIT to activate reselling mode."); llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); } else { state reselling; } } /////////////////////////////////////// dataserver() //////////////////////////////// dataserver(key id, string data) { if (id == reqNameCreator) { reqNameCreator=NULL_KEY; creator_name=data; if (perm_debit && creator_name!="") state reselling; } if (id == reqNameOwner) { reqNameOwner=NULL_KEY; owner_name=data; if (perm_debit && creator_name!="") state reselling; } } /////////////////////////////////////// run_time_permissions() /////////////////////// run_time_permissions(integer perm) { if (perm & PERMISSION_DEBIT) { perm_debit=TRUE; if (creator_name != "" && owner_name!="") { state reselling; } } else { state not_reselling; } } ////////////////////////// state_exit() /////////////////////////////////////// state_exit() { already_running=TRUE; } } ////////////////////////////////////////////// reselling ///////////////////////////////////////////// state reselling { /////////////////////////////////// state_entry() //////////////////////////////////////// state_entry() { llSetPayPrice(pay_price, [ pay_price, PAY_HIDE, PAY_HIDE, PAY_HIDE ]); llListen(9, "", llGetOwner(), "STOP RESELLING"); } ////////////////////////////////// money() /////////////////////////////////////////////// money(key id, integer amount) { if (amount < pay_price) { llWhisper(0, "This item costs " + (string)pay_price + " L$, you paid " + (string)amount + " L$. Refunding your money."); llGiveMoney(id, amount); } else { if (amount > pay_price) { llWhisper(0, "This item costs " + (string)pay_price + " L$, you paid " + (string)amount + " L$. Here is your change."); llGiveMoney(id, amount - pay_price); } llGiveInventory(id, resell_item); ++num_sold; integer share; integer num_shares=llGetListLength(pay_share); if (num_sold > num_shares) share=llList2Integer(pay_share,num_shares - 1); else share=llList2Integer(pay_share,num_sold); integer keep=pay_price - share; llGiveMoney(creator,keep); llInstantMessage(llGetOwner(), "Resell no. " + (string)num_sold + " of item: '" + resell_item + "' for price " + (string)pay_price + " L$. Your share: " + (string)share + " L$. Paid to " + creator_name + " " + (string)keep + " L$."); llInstantMessage(creator, "Resell no. " + (string)num_sold + " of item: '" + resell_item + "' for price " + (string)pay_price + " L$. Your share: " + (string)keep + " L$. Kept by " + owner_name + " " + (string)share + " L$."); } } //////////////////////////////////////// listen() /////////////////////////////////////// listen(integer chan, string name, key id, string message) { if (chan==9 && llToUpper(message)=="STOP RESELLING") { state not_reselling; } } } //////////////////////////////////// not_reselling ////////////////////////////////////////// state not_reselling { ////////////////////////////////////////// state_entry() ///////////////////////////////// state_entry() { llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]); llOwnerSay("Currently not reselling."); llListen(9, "", llGetOwner(), "START RESELLING"); } ///////////////////////////////////////////// on_rez() ///////////////////////////////////// on_rez(integer start_param) { llResetScript(); } ///////////////////////////////////////////// listen() //////////////////////////////////// listen(integer chan, string name, key id, string message) { if (chan == 9 && id == llGetOwner() && llToUpper(message) == "START RESELLING") { state default; } } }