Jump to content

HELP WITH SCRIPTING A MONEY TREE


Sharelle Aurelia
 Share

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

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

Recommended Posts

I'm a noob when it comes to scripting. Yet, I want script(s) that I can add into an object that gives out lindens to resident when clicked.

e.g. a money tree with a dollar bill (leaf)

I tried looking at this script below but it only confused me as I tried to turn it as my own. Again, I'm new to scripting and don't know much about it.

Leaf Prim:

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1
2 // Put this in a a prim
3 // Put this prim in the server
4 // It will fall and if touched, send money
5
6 integer channel = -76576; // a very secret number/password also found in the boxes that fall.
7
8 integer ready = FALSE;
9
10 default
11 {
12 on_rez(integer param)
13 {
14 ready = param; // for safety, we make it so if rezzed with no param, it does not spend money
15 llSetTimerEvent((float) param);
17 }
18 timer()
19 {
20 llDie();
21 }
22 touch_start(integer total_number)
23 {
24 if(ready) {
25 llSay(channel,llDetectedKey(0));
26 llDie();
27 }
28 }
29 }
 
Makes The Tree:
This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // Add a prim to this prims inventory with the FallingScript in it.
2
3 integer Amount = 1; // Give one Linden each time.
4 integer Max = 100; // the max $L to give away, then stop giving
5
6 integer rezTime = 10; // The boxes will rez for 10 seconds, then die
7 float DIST = 10; // Boxes will be rezzed within this radius of the giver. (!!! MAX = 10 )
8 // How often to rez objects
9 float min = 60; // one minute minimum
10 float max = 300; // 5 minutes sometimes
11 integer channel = -76576; // a very secret number/password also found in the boxes that fall.
12 integer Given;
13 default
14 {
16 {
18 }
19
20 run_time_permissions(integer permissions)
21 {
22 if(permissions & PERMISSION_DEBIT)
23 {
24 llListen(channel,llGetInventoryName(INVENTORY_OBJECT,0),"",""); // listen for givers we rezzed by name
25 llSetTimerEvent(llFrand(max - min) + min);
26 }
27 }
28
29 timer()
30 {
31 vector myPos = llGetPos(); // this giver is HERE
32 myPos.x = llFrand(DIST*2) - DIST + myPos.x; // Make it +/- DIST away
33 myPos.y = llFrand(DIST*2) - DIST + myPos.y;
34
35 // And rez it with a start parameter
37 }
38
39 listen(integer channel, string name, key id, string message)
40 {
41 if(Given > Max) {
42 llSetTimerEvent(0); // stop giving
43 llInstantMessage(llGetOwner(), "Out of money to give");
44 llSetText("Balance: 0 " , <1,0,0>,1.0); // red text
45 return;
46 }
47
48 Given += Amount;
49 key avatarKey = (key) message;
50 llGiveMoney(avatarKey, Amount);
51 llSetText("Balance: " + (string) (Max - Given), <0,0,1>,1.0);// Green text
52 }
53
54 }
Edited by Dezonnia
to correct sentence
Link to comment
Share on other sites

These scripts didn't work for me. It didn't show hover texts above the object (tree) of the total amount.  My goal is to make this script object drops randomly for 30-60 secs then dies if not clicked. Yet, I want to be able pay any amount of lindens into the object. Also, it only pays out L$1 (or whatever amount) when someone touches it. I would like a hover text showing the total amount paid into the object as well as show the amount left (as residents click on it). It would be even better if the object allows the same resident to click certain amount of times (maybe once or twice within 24 or 48 hours?).  

Edited by Dezonnia
Link to comment
Share on other sites

OK. back up and stop everything you're doing - If you want to learn scripting ... This is not a bad idea or bad first "real" project, it covers quite a lot of the basics of SL scripting and interacting with SL and avatars, objects and money.

 

Trying to take someone else's script is where you're going wrong - as any programmer will tell you - hell is other people's code.

 

What you need to do is start from scratch with your own code, refer to other scripts if you need to see how things were done, but never just copy paste their garbage into yours.

Step one is to define how the money tree is going to work, you can then work though that step by step solving a lot of very small easy problems till you have a finished thing.

The best place to start any new project like this is on paper.

My recommendations would be to have a prim with 2 scripts in. One is the main script that does all the work, rezzes things, handles accounting, incoming and outgoing L$ and debt permissions. The second is a small dormant script that you inject into the money after you rez it, this waits for someone to click and informs the main script and then deletes itself.

You will need to work out rezzing with pseudo random positioning, injecting a script into a freshly rezzed prim, prim to prim messaging, counting the money in and out, debt permissions, friendly human readable messaging and stats.

last but not least, security as money is involved  .. how can your script be abused, can people spoof the messages from the money and get cash out of it. Basic human detection to weed out the simpler automated bots (that killed all the original money trees), etc etc.

 

Tackle one problem at a time, don't be afraid to ask questions or for pointers, don't trash your work with garbage copy pasted from other scripts you found online for free, and by the end of the project you will be well equipped to script just about anything you could ever want in SL.

  • Like 2
Link to comment
Share on other sites

18 minutes ago, Coffee Pancake said:

Step one is to define how the money tree is going to work, you can then work though that step by step solving a lot of very small easy problems till you have a finished thing.

I'd split "step one" into a few more granular steps:

First you decide on "big picture" idea of how it works, "Ex. I want a Tree with leaves, when someone touches a leaf they get money . . ." with a few more broad "when this happens that happens; I want it to have a X thing that does Y".

Then, you decide on a specific implementation for each of the broad ideas, converting general ideas into SL-specific terms: "Ex. The leaves will be separate SL temp-on-rez objects, XYZ will be presented as object-text on the tree etc."

You'd be surprised at how many people seem to get stuck on:

"I want to do X!" "You can't do X, why do you want to do X?" "Because that makes it look like Y is happening!" "So what if you did Z?" "But I really want to do X!"

--

On specific implementation details, my go-to would be to have the leaves turn visible/invisible and be linked to the main tree rather than rezzing separate leaf objects. There are lots of pros/cons to any specific implementation method. Some projects just fall into place, other-times it's like a Sudoku with an accidental wrong answer filled in, so you keep jumping around choosing a different option until it all meshes together. ...

  • Like 1
Link to comment
Share on other sites

I appreciate everyone for replying.

 

Anyway, I tried to fiddle with the original version script (trying to turn it into my own) for hours with no luck. The only good came out out of trying were I started out scripting my tree (branches) with a dollar sign emitter with sounds.  When clicked on the tree branch a flowing of cash signs comes out with a brief sound and if touching (or clicking) the dollar bill (the leaf) it disappears but that's about it. lol

I got frustrated and stopped trying due to getting a headache. SMDH 

As stated before, 

my goal were to make this script for object that drops (dollars out the tree) randomly for 30-60 secs then dies if not clicked within those seconds. Also, I want to be able pay any amount of lindens into the object. In addition, to be able set specific payments e.g. only pays out L$1 (or whatever amount) when someone touches it; along a hover text showing the total amount paid into the object as well as showing the amount left (after each clicks ). It would be even better if the object allows certain amount of times to be click by a resident (maybe once or twice within 24 or 48 hours?).  

Right now, I am stuck at what little I did with the tree and I don't know if I will continue this project. Thanks for all responses. Even if it's not helpful.

Edited by Dezonnia
to correct sentence
Link to comment
Share on other sites

I had nothing better to do.

Money object:

default
{
    // Let the rezzer know who touched this object.
    touch_start(integer total_number)
    {
        list data = llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]);
        key rezzer = llList2Key(data, 0);

        if (rezzer) {
            integer channel = (integer)("0x" + (string)rezzer);
            llRegionSayTo(rezzer, channel, llDetectedKey(0));
            llDie();
        }
    }

    // Set the object's lifetime based on rez parameter from llRezObject.
    on_rez(integer seconds)
    {
        if (seconds) {
            llSetTimerEvent(seconds);
            llSetStatus(STATUS_PHYSICS,TRUE);
        }
    }

    timer()
    {
        llDie();
    }
}

Money rezzer:

integer channel; // Unique channel is generated for this rezzer

string money_object = "money"; // Name of rezzed object
integer money_amount = 1; // Amount paid per rez
integer money_max = 1; // Max lindens to pay out
integer money_given; // Running total

float rez_radius = 10; // Should be no greater than 10
float timer_min = 5; // seconds to rez
float timer_max = 10; // seconds to rez
integer rez_lifetime = 10; // Seconds before money object disappears

default
{
    // Main setup
    run_time_permissions(integer permissions)
    {
        if ((permissions & PERMISSION_DEBIT) == FALSE) {
            llOwnerSay("Status: No debit permission, can't give lindens!");
            return;
        }

        if (money_object == "") {
            llOwnerSay("Status: No money object defined!");
            return;
        }

        channel = (integer)("0x" + (string)llGetKey());

        llListen(channel, money_object, "", "");
        llSetTimerEvent(timer_min + llFrand(timer_max - timer_min));

        llSetText("Balance: " + (string)money_max, <0,1,0>, 1.0);
        llOwnerSay("Status: Ready");
    }

    // Rez a money giver within a random position around this object, then randomize timer.
    timer()
    {
        vector pos = llGetPos();
        pos.x += llFrand(rez_radius * 2) - rez_radius;
        pos.y += llFrand(rez_radius * 2) - rez_radius;

        llRezObject(money_object, pos, ZERO_VECTOR, ZERO_ROTATION, rez_lifetime);
        llSetTimerEvent(timer_min + llFrand(timer_max - timer_min));
    }

    // Give money to a key heard from a rezzed object. Shut down when threshold is reached.
    listen(integer channel, string name, key id, string message)
    {
        if (money_given >= money_max) {
            return;
        }

        key avatar_key = (key)message;

        if (avatar_key == NULL_KEY) {
            return;
        }

        llGiveMoney(avatar_key, money_amount);
        money_given += money_amount;

        if (money_given < money_max) {
            llSetText("Balance: " + (string)(money_max - money_given), <0,1,0>, 1.0);
        } else {
            llSetTimerEvent(0);
            llSetText("Balance: 0", <1,0,0>, 1.0);
            llInstantMessage(llGetOwner(), "Out of money to give");
        }
    }

    on_rez(integer start_param)
    {
        llResetScript();
    }

    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
}

 

Edited by Wulfie Reanimator
  • Like 1
  • Thanks 3
Link to comment
Share on other sites

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