Jump to content

Need Help With This Random Giver Script!


DarkEmperor13
 Share

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

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

Recommended Posts

Hey guys I found this script on the wiki:

default
{
    touch_start(integer num_detected)
    {
    //  the key of the avatar touching
        key id = llDetectedKey(0);
 
        integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
    //  random >> [0.0, max)
        randomIndex = (integer)llFrand(randomIndex);
 
        string itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
 
        llGiveInventory(id, itemName);
    }
}

Ok so it gives you a random item from the prim's(that this script is in) inventory. Now my question is how can you make the script remove the item once it is given?

Link to comment
Share on other sites

llRemoveInventory is what you are looking for:

default
{
    touch_start(integer num_detected)
    {
    //  the key of the avatar touching
        key id = llDetectedKey(0);
 
        integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
    //  random >> [0.0, max)
        randomIndex = (integer)llFrand(randomIndex);
 
        string itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
 
        llGiveInventory(id, itemName);

        llRemoveInventory(itemName); //Remove the item from inventory
    }
}

KEEP IN MIND: This permanently removes the item from the object's inventory! It does not go to your trash, or a trash folder in the object. The item will be gone for good!

  • Like 1
Link to comment
Share on other sites

13 minutes ago, DarkEmperor13 said:

just in case, is there a way to make it go to ur trash?

No, but you could give it to yourself at the same time

default
{
    touch_start(integer num_detected)
    {
    //  the key of the avatar touching
        key id = llDetectedKey(0);
 
        integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
    //  random >> [0.0, max)
        randomIndex = (integer)llFrand(randomIndex);
 
        string itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
 
        llGiveInventory(id, itemName);
	llGiveInventory(llGetOwner(),itemName);

        llRemoveInventory(itemName); //Remove the item from inventory
    }
}

 

Link to comment
Share on other sites

Scripting is 90% about logic, and sadly, it's difficult to learn by copying down someone else's logic.  The best way to address a problem like this is to stand back and take a deep breath. then:

1. Think the problem through carefully, one step at a time.

2. If it's a complicated problem, solve it in small pieces.

3. Test everything, using plenty of llOwnerSay messages to yourself so that you can see exactly what the script is doing.

And of course, my own favorite rule:

4. Trust only your own work. If you found a free script somewhere, that's fine, but assume that you can do better if you just start fresh. Other people make mistakes, or at least different assumptions, so fall into your own potholes -- not theirs. You can get great ideas from other people's scripts, but the best ideas for solving your problem are the ones you figure out yourself. ;)

Link to comment
Share on other sites

I know this isn't relevant to this post or whatever u call u, but I need to know how I can get this code to remove object from inventory.

default

    
{
    state_entry() {
        llSetText("",<1,1,1>,1);
    }
    touch_start(integer param)
    {
        llGiveInventory(llDetectedKey(0),"Box");
    }
    
}

this is for giving object with name given in script to anyone who touches the prim

Link to comment
Share on other sites

4 minutes ago, DarkEmperor13 said:

I've tried llremoveinventory(itemName), llremoveinventory(llDetectedKey(0),"Box") and even llremoveinventory("Box")

 

edited in response to Love Zhaoying: oh really? How do u do it?

I best let someone else answer how to make something “no copy”, I want to go get a “good” answer!

Some if your attempts at llRemoveInventory should not have compiled. See http://wiki.secondlife.com/wiki/LlRemoveInventory

Link to comment
Share on other sites

6 minutes ago, Love Zhaoying said:

I best let someone else answer how to make something “no copy”,

Um....   Like this:

86d54ef7284b38cf4df1fc1ae182df8d.png

UNclick the box marked Next Owner: COPY.  You can do that on any asset that you own (Object, Script, notecard, animation, sound ....).

Link to comment
Share on other sites

3 minutes ago, Love Zhaoying said:

Ok, wasn’t sure if rezzed copy or in-inventory.

Either way. Right click, select Properties, and then set your next owner perms.  You can never make something MORE permissible for the next guy, but you can always make it LESS permissible.  The only catch at all is that Next Owner perms only become permanent on an Object when it is rezzed, you you don't want to set perms on objects while they are in your inventory.  Set them on rezzed copies, which you then take to inventory.

Edited by Rolig Loon
  • Like 2
Link to comment
Share on other sites

18 minutes ago, Rolig Loon said:

Either way. Right click, select Properties, and then set your next owner perms.  You can never make something MORE permissible for the next guy, but you can always make it LESS permissible.  The only catch at all is that Next Owner perms only become permanent on an Object when it is rezzed, you you don't want to set perms on objects while they are in your inventory.  Set them on rezzed copies, which you then take to inventory.

And then, the giver script will give the no-copy version, thusly removing from the object’s Inventory?

Link to comment
Share on other sites

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