ZenMondo Wormser
Registered User
Join date: 19 Mar 2006
Posts: 26
|
03-21-2007 01:06
//////////////////////// // Function GetNewInventoryName by ZenMondo Wormser // // This function returns a list of the names of // inventory items added to an object's inventory // since the last time the function was called. // // This function works by keeping a list of inventory items // and comparing against that list as inventory changes. // // NOTE: If items are deleted between calls and nothing is added // this function will return an empty list. ////////////////////////
list gOld_Inventory; //This stores the Inventory since the last function call. //It is global so it persists between function calls. //It may also be handy to have a list of your object's inventory.
list GetNewInventoryName() { list found_new = []; //This list will contain the names of New Inventory items. integer inventory_type = INVENTORY_ALL; //Change to look at inventory type you want. integer inventory_num = llGetInventoryNumber(inventory_type); list new_inventory = []; //This list will contain the current inventory. integer counter = 0; while(counter < inventory_num) { new_inventory = (new_inventory=[]) + new_inventory + llGetInventoryName(inventory_type, counter); counter ++; } integer list_length = llGetListLength(new_inventory); counter = 0; list scratch; while(counter < list_length) { scratch = llList2List(new_inventory, counter, counter); if(llListFindList(gOld_Inventory, scratch) == -1) //New Inventory Object { found_new += llList2String(scratch,0); //Add the name of the new inventory item to the found_new list } counter ++; } gOld_Inventory = new_inventory; //Store the Inventory List to be compared the next time the function is called. return found_new; //Return a list of the new inventory items. }
default { state_entry() { GetNewInventoryName(); //Populate the list on reset. }
touch_start(integer num_detected) { /////////// // Example Use in touch_start() // Because Multiple Items could have been // added between calls we work through // the list that is retunred. /////////// list new_inv = GetNewInventoryName(); llSay(0, "New Inventory Items:"); integer list_len = llGetListLength(new_inv); integer counter; for(counter = 0; counter < list_len; counter++) { llSay(0, llList2String(new_inv, counter)); } } changed(integer mask) { ////////////////// // Example Used in changed() // This is much simpler, as changed() // will be triggered each time something // is added to the object's inventory // resulting in only one result in the // returned list from GetNewInventoryName() //////////////////// if(mask & CHANGED_INVENTORY) { list new_inv = GetNewInventoryName(); llSay(0, "New Inventory Item:" + llList2String(new_inv, 0)); } } }
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
Discussion Thread
03-21-2007 04:26
_____________________
i've got nothing. 
|
Herfulnerful Holsworthy
Registered User
Join date: 27 Nov 2006
Posts: 8
|
I Am Wondering If ...
05-03-2007 18:02
What are the chances of adapting this script to create a notecard that continually gets updated as the script recognizes new items? Of course, the script will have to initially create the starter notecard ... any takers on the idea? From: ZenMondo Wormser //////////////////////// // Function GetNewInventoryName by ZenMondo Wormser // // This function returns a list of the names of // inventory items added to an object's inventory // since the last time the function was called. // // This function works by keeping a list of inventory items // and comparing against that list as inventory changes. // // NOTE: If items are deleted between calls and nothing is added // this function will return an empty list. ////////////////////////
list gOld_Inventory; //This stores the Inventory since the last function call. //It is global so it persists between function calls. //It may also be handy to have a list of your object's inventory.
list GetNewInventoryName() { list found_new = []; //This list will contain the names of New Inventory items. integer inventory_type = INVENTORY_ALL; //Change to look at inventory type you want. integer inventory_num = llGetInventoryNumber(inventory_type); list new_inventory = []; //This list will contain the current inventory. integer counter = 0; while(counter < inventory_num) { new_inventory = (new_inventory=[]) + new_inventory + llGetInventoryName(inventory_type, counter); counter ++; } integer list_length = llGetListLength(new_inventory); counter = 0; list scratch; while(counter < list_length) { scratch = llList2List(new_inventory, counter, counter); if(llListFindList(gOld_Inventory, scratch) == -1) //New Inventory Object { found_new += llList2String(scratch,0); //Add the name of the new inventory item to the found_new list } counter ++; } gOld_Inventory = new_inventory; //Store the Inventory List to be compared the next time the function is called. return found_new; //Return a list of the new inventory items. }
default { state_entry() { GetNewInventoryName(); //Populate the list on reset. }
touch_start(integer num_detected) { /////////// // Example Use in touch_start() // Because Multiple Items could have been // added between calls we work through // the list that is retunred. /////////// list new_inv = GetNewInventoryName(); llSay(0, "New Inventory Items:"); integer list_len = llGetListLength(new_inv); integer counter; for(counter = 0; counter < list_len; counter++) { llSay(0, llList2String(new_inv, counter)); } } changed(integer mask) { ////////////////// // Example Used in changed() // This is much simpler, as changed() // will be triggered each time something // is added to the object's inventory // resulting in only one result in the // returned list from GetNewInventoryName() //////////////////// if(mask & CHANGED_INVENTORY) { list new_inv = GetNewInventoryName(); llSay(0, "New Inventory Item:" + llList2String(new_inv, 0)); } } }
|
Herfulnerful Holsworthy
Registered User
Join date: 27 Nov 2006
Posts: 8
|
Could this script also include ...
05-03-2007 18:04
a notecard that gets created initially and is retained to be updated as the script recognizes the new object? Anyone care to take this on? From: ZenMondo Wormser //////////////////////// // Function GetNewInventoryName by ZenMondo Wormser // // This function returns a list of the names of // inventory items added to an object's inventory // since the last time the function was called. // // This function works by keeping a list of inventory items // and comparing against that list as inventory changes. // // NOTE: If items are deleted between calls and nothing is added // this function will return an empty list. ////////////////////////
list gOld_Inventory; //This stores the Inventory since the last function call. //It is global so it persists between function calls. //It may also be handy to have a list of your object's inventory.
list GetNewInventoryName() { list found_new = []; //This list will contain the names of New Inventory items. integer inventory_type = INVENTORY_ALL; //Change to look at inventory type you want. integer inventory_num = llGetInventoryNumber(inventory_type); list new_inventory = []; //This list will contain the current inventory. integer counter = 0; while(counter < inventory_num) { new_inventory = (new_inventory=[]) + new_inventory + llGetInventoryName(inventory_type, counter); counter ++; } integer list_length = llGetListLength(new_inventory); counter = 0; list scratch; while(counter < list_length) { scratch = llList2List(new_inventory, counter, counter); if(llListFindList(gOld_Inventory, scratch) == -1) //New Inventory Object { found_new += llList2String(scratch,0); //Add the name of the new inventory item to the found_new list } counter ++; } gOld_Inventory = new_inventory; //Store the Inventory List to be compared the next time the function is called. return found_new; //Return a list of the new inventory items. }
default { state_entry() { GetNewInventoryName(); //Populate the list on reset. }
touch_start(integer num_detected) { /////////// // Example Use in touch_start() // Because Multiple Items could have been // added between calls we work through // the list that is retunred. /////////// list new_inv = GetNewInventoryName(); llSay(0, "New Inventory Items:"); integer list_len = llGetListLength(new_inv); integer counter; for(counter = 0; counter < list_len; counter++) { llSay(0, llList2String(new_inv, counter)); } } changed(integer mask) { ////////////////// // Example Used in changed() // This is much simpler, as changed() // will be triggered each time something // is added to the object's inventory // resulting in only one result in the // returned list from GetNewInventoryName() //////////////////// if(mask & CHANGED_INVENTORY) { list new_inv = GetNewInventoryName(); llSay(0, "New Inventory Item:" + llList2String(new_inv, 0)); } } }
|