blog:opensim:scripts:prim_inv_trans
This is an old revision of the document!
Table of Contents
Prim Inventory Transfer
These are the scripts for transferring inventory from one object to another, and allowing scripts to be transferred and set to a running state. These are the scripts used in the demonstration video prim inventory transfer.
Receiver
- receiver.ossl
//YEngine: yoptions; constant __DEBUG__ = TRUE; constant SCRIPT_PIN = 72743825; constant updateChan = -4744320; integer lhandle; debug( string text ){ if( __DEBUG__ ){ llOwnerSay( text ); } } endListen(){ if( lhandle != 0 ){ llListenRemove( lhandle ); lhandle = 0; } llSetTimerEvent(0.0); } default { state_entry() { llSetText("Receiver",<1,0.685,0>,1.0); llSetRemoteScriptAccessPin(SCRIPT_PIN); debug("Access pin set"); } touch_start(integer num){ if( llDetectedKey(0) == llGetOwner() ){ lhandle = llListen( updateChan, "", "", "" ); llSetTimerEvent(60.0); debug("Waiting for updater"); } } timer(){ endListen(); } listen(integer channel, string name, key id, string msg){ if( llGetOwnerKey( id ) == llGetOwner() ){ if( msg == "UPDATE-PING" ){ debug("Updater identified, sending READY"); endListen(); llRegionSayTo( id, updateChan, "UPDATE-PONG" ); } } } }
Sender
- sender.ossl
//YEngine: yoptions; constant __DEBUG__ = TRUE; constant SCRIPT_PIN = 72743825; constant updateChan = -4744320; integer lhandle; debug( string text ){ if( __DEBUG__ ){ llOwnerSay( text ); } } endListen(){ if( lhandle != 0 ){ llListenRemove( lhandle ); lhandle = 0; } llSetTimerEvent(0.0); } // Get inventory list // remove this script from list integer deliverItems( key id ){ list items = osGetInventoryNames( INVENTORY_ALL ); integer l = llGetListLength( items ); integer sent = 0; list results; list scripts; for( integer i = 0; i < l; i++ ){ string name = llList2String( items, i ); if( llGetInventoryType( name ) != INVENTORY_SCRIPT ){ results += [name]; } else if( name != llGetScriptName() ){ scripts += [name]; } } // make sure we deliver items before scripts if( results != [] ){ // deliver everything except the scripts // We need to give a folder name, but no folder is created in an object llGiveInventoryList( id, "AnyName", results ); sent = llGetListLength( results ); } if( scripts != [] ){ l = llGetListLength( scripts ); for( integer i = 0; i < l; i++ ){ debug("Delivering script #"+(i+1)+"/"+l); llRemoteLoadScriptPin( id, llList2String( scripts, i ), SCRIPT_PIN, TRUE, 15 ); sent++; } } return sent; } default { state_entry() { llSetText("Sender",<1,0.685,0>,1.0); debug("Script running"); } touch_start(integer num){ if( llDetectedKey(0) == llGetOwner() ){ lhandle = llListen( updateChan, "", "", "" ); llSetTimerEvent(5.0); debug("Seaching for receiver"); llWhisper( updateChan, "UPDATE-PING" ); } } timer(){ endListen(); } listen(integer channel, string name, key id, string msg){ if( llGetOwnerKey( id ) == llGetOwner() ){ if( msg == "UPDATE-PONG" ){ debug("Receiver found"); endListen(); integer sent = deliverItems( id ); debug("Inventory sent: "+sent); } } } }
blog/opensim/scripts/prim_inv_trans.1748951132.txt.gz · Last modified: by Phil Ide