LlSensorRepeat
De DigiWiki.
Version du 28 septembre 2012 à 07:30 par Djphil (discuter | contributions)
// Written by Steamy Latte. // Scans every 30 seconds for visitors within 10 meters. // Reports new visitors to object owner when she is in range. string AllAgents; string OwnerName; default { state_entry() { // arc=PI is a sphere, you could look more narrowly in the direction object is facing with PI/2, PI/4 etc. // don't repeat this too often to avoid lag. llSensorRepeat("", "", AGENT, 10.0, PI, 30.0); } sensor(integer num_detected) { string thisAgent = ""; integer agentNum; for (agentNum=0; agentNum<num_detected; agentNum++) { key thisKey = llDetectedKey(agentNum); string thisAgent = llDetectedName(agentNum); if (thisKey == llGetOwner()) { if (AllAgents != "") { llOwnerSay("We've had the following visitors:" + AllAgents); AllAgents = ""; } } else if (llSubStringIndex(AllAgents+"\n", "\n"+thisAgent+"\n") < 0) { AllAgents = AllAgents + "\n" + thisAgent; } } } }
// Written by Evans Love. // (Limited to most recent 200 names by Void Singer to prevent eventual Stack/Heap Collision + clean up) // Continuously scans for visitors within 10 meters and reports new visitors to object owner. //------------------------------------------------------------------------------------- // Channel integer RESPONSE_CHANNEL = -100; // Variables list VISITOR_LIST; float SCAN_RANGE = 10.0; float SCAN_INTERVAL = 0.1; //Program default { state_entry ( ) { llSensorRepeat ( "", NULL_KEY, AGENT, SCAN_RANGE, PI, SCAN_INTERVAL ); } sensor ( integer number_detected ) { integer agent_number; for ( agent_number = 0; agent_number < number_detected; agent_number ++ ) // Iterates through all Agents detected. { string this_agent_name = llDetectedName ( agent_number ); // Working Agent Name key this_agent_key = llDetectedKey ( agent_number ); // Working Agent Key integer index = llListFindList ( VISITOR_LIST, [ this_agent_name ] ); if ( index == -1 ) // If the Agent is not on the list. { VISITOR_LIST = [this_agent_name] + llList2List( VISITOR_LIST, 0, 198 ); // Appends the Agent to the Visitor List llDialog ( this_agent_key, "Welcome!", "Ok", RESPONSE_CHANNEL ); llOwnerSay ( this_agent_name ); } else // If the Agent is already on the list. { } } } no_sensor ( ) { } }