Difference between revisions of "User:Kephra Nurmi/lsDistributor"

From Second Life Wiki
Jump to navigation Jump to search
(New page: == lsDistributor == lsDistributor is a simple 'try' and 'buy' vendor system. I once wrote a complex vendor system, a notecard driven feature ridden beast. But then I found a much simpler ...)
 
Line 11: Line 11:
   
   
<pre>
<pre>
// .lsDistributor client (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License
integer channel = -19;
integer channel = -19;
integer price = 0;
integer price = 0;
Line 40: Line 42:


<pre>
<pre>
// .lsDistributor server (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License
integer channel = -19;
integer channel = -19;


Line 74: Line 78:


<pre>
<pre>
// .lsDistributor share (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License
default {
default {
     state_entry() {
     state_entry() {
Line 105: Line 111:


<pre>
<pre>
// .lsDistributor lautsprecher (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License
integer channel = -19;
integer channel = -19;



Revision as of 17:22, 3 May 2009

lsDistributor

lsDistributor is a simple 'try' and 'buy' vendor system. I once wrote a complex vendor system, a notecard driven feature ridden beast. But then I found a much simpler solution, compatible with SLX magic box and a setup that does not require any notecards!

The idea is a simulator wide client server system using llRegionSay. The server script could be a plugin in the SLX magic box, while the clients are configured by object name and object description.

Script: .lsDistributor client

The client script will sell a product with same name as the object name, for a price named in object description. The object description must start with L$ to configure the price. Dont forget to mark them as [x] show in search, to include every product in second life search. The system does not support multi prim, multi product vendors. IMHO those are a bad idea, since search allows to search for objects. So the object name and description became one of the most important advertising opportunities you can get for nearly cheap.

// .lsDistributor client (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License

integer channel = -19;
integer price = 0;
string product = "";

default { 
    state_entry() {
        string s = llList2String(llCSV2List(llGetObjectDesc()),0);
        if ((llGetSubString(s,0,1) == "L$") || (llGetSubString(s,0,1) == "l$")) {
            product = ","+llGetObjectName();
            price = (integer)llGetSubString(s,2,-1);
            llSetPayPrice(PAY_HIDE, [price, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        } else
            llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
    }
    touch_start(integer n) {
        key av = llDetectedKey(0);
        llRegionSay(channel,"try,"+(string)av+","+llKey2Name(av)+product);
    }
    money(key id, integer amount) {
        llRegionSay(channel,"buy,"+(string)id+","+llKey2Name(id)+product);
    }
}

Script: .lsDistributor server

The server could be used as a plugin for the SLX magic box, so you can sell the same products to SLX and in game from the same server box. The objects in the box, must have the same name as the object names of the vendor clients.

// .lsDistributor server (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License

integer channel = -19;

default {
    state_entry() {
        llListen( channel, "", NULL_KEY, "" );
    }
    listen( integer channel, string name, key id, string msg ) {
        key k = id;
        if (llGetAgentInfo(k)<=0) k = llGetOwnerKey(k);
        if (llGetOwner() != k) return;
        list tmp = llCSV2List(msg);
        string cmd = llList2String(tmp,0);
        if ("buy" == cmd) {
            key av = llList2Key(tmp,1);
            string name = llList2String(tmp,2);
            string item = llList2String(tmp,3);
            if (llGetInventoryType(item) != INVENTORY_NONE) {
                llGiveInventory(av,item);
                llInstantMessage(llGetOwner(),name+" purchased "+item);
                llInstantMessage(av,"Thanks for buying "+item);
            } else {
                llInstantMessage(llGetOwner(),"ERROR: Item sold to "+name+" does not exist: "+item);
                llInstantMessage(av,"ERROR: Item sold to "+name+" does not exist: "+item+"   ... please inform the owner of the vendor.");
            }
        }
    }
}

Script: .lsDistributor share,10,2682eb10-ee55-46a6-bc49-0f09a39d152b

This script could be used as a plugin for the vendor clients to pay commission. The script is configures by its own name to pay a percentage. It would pay 10% to me, in this example case. So please change the uuid before use.

// .lsDistributor share (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License

default {
    state_entry() {
        llRequestPermissions( llGetOwner(), PERMISSION_DEBIT );
    }
    run_time_permissions(integer perms) {
        if (perms & PERMISSION_DEBIT) state running;
    }
    changed(integer change) {
        if (change & CHANGED_OWNER) llResetScript();
    }
}

state running {
    money(key id, integer amount) {
        list tmp = llCSV2List(llGetScriptName());
        if (llGetListLength(tmp) != 3) return;
        integer give = amount * llList2Integer(tmp,1) / 100;
        if (0 < give)
            llGiveMoney(llList2Key(tmp,2), give);
    }
    changed(integer change) {
        if (change & CHANGED_OWNER) llResetScript();
    }
}

Script: .lsDistributor lautsprecher

The 'try' part of the vendor really depends on the kind of product you want to sell. It could be a rezzer, a notecard or demo giver, or anything you can imagine. The following example implements a speaker to play sounds.

// .lsDistributor lautsprecher (c) 2008-2009 by Kephra Nurmi under Creative Commons Attribution-Share Alike 3.0 License

integer channel = -19;

default {
    state_entry() {
        llListen( channel, "", NULL_KEY, "" );
    }
    listen( integer channel, string name, key id, string msg ) {
        key k = id;
        if (llGetAgentInfo(k)<=0) k = llGetOwnerKey(k);
        if (llGetOwner() != k) return;
        list tmp = llCSV2List(msg);
        string cmd = llList2String(tmp,0);
        if ("try" == cmd) {
            key av = llList2Key(tmp,1);
            string name = llList2String(tmp,2);
            string item = llList2String(tmp,3);
            if (llGetInventoryType(item) == INVENTORY_SOUND) {
                llPlaySound(item,1.0);
            }
        }
    }
}