Difference between revisions of "LlCollisionFilter"

From Second Life Wiki
Jump to navigation Jump to search
 
(19 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|inject-2={{Issues/SVC-2490}}{{LSL_Function/uuid|id|object=*|pd=filter by}}
{{LSL_Function/boolean|accept|pd=|ph=|td=only process collisions that match|fd=instead excludes matches}}
|func_id=110|func_sleep=0.0|func_energy=10.0
|func_id=110|func_sleep=0.0|func_energy=10.0
|sort=CollisionFilter
|sort=CollisionFilter
|func=llCollisionFilter
|func=llCollisionFilter
|p1_type=string|p1_name=name
|p1_type=string|p1_name=name|p1_desc=filter for specific object name or avatar {{LSLGC|Avatar/Name|legacy name}}|p1_hover=filter for specific object name or avatar legacy name
|p2_type=key|p2_name=id
|p2_type=key|p2_name=id
|p3_type=integer|p3_name=accept
|p3_type=integer|p3_subtype=boolean|p3_name=accept
|func_footnote=if '''accept''' == {{LSLG|TRUE}}, only accept collisions with objects '''name''' and '''id''' (either is optional), otherwise with objects not '''name''' or '''id'''
|func_footnote=If {{LSLP|accept}} == [[TRUE]], only accept collisions with objects {{LSLP|name}} AND {{LSLP|id}} (either is optional), otherwise with objects not {{LSLP|name}} AND {{LSLP|id}}<br/>
If {{LSLP|name}} or {{LSLP|id}} are blank they are not used to filter incoming messages (or you could say they match everything).
If {{LSLP|id}} is an invalid key or a [[NULL_KEY|null key]], it is considered blank.<br/>
|func_desc=Sets the collision filter, exclusively or inclusively.
|func_desc=Sets the collision filter, exclusively or inclusively.
|return_text
|return_text
|spec
|spec
|caveats
|caveats=
*Any call of llCollisionFilter in the same event as [[llVolumeDetect]] changing (not just being called, but actually moving from [[FALSE]] to [[TRUE]] or vice versa) will be disregarded (before or after), '''if''' the event handler previously called a user-defined function. See [[#SVC-2490]]
**You can get around this by calling them in separate events, such as [[touch_start]] and [[touch_end]].
*Damage caused by [[llSetDamage]] will still apply to a filtered avatar.
**Consequently, the object will immediately die on collision with the avatar. (And kill the avatar their health reaches 0.)
|constants
|constants
|examples=
|examples=
Stop filtering:
Stop filtering:
<lsl>llCollisionFilter("", NULL_KEY, TRUE);</lsl>
<source lang="lsl2">llCollisionFilter("", NULL_KEY, TRUE);</source>
Filter out all collisions:
Filter out all collisions:
<lsl>llCollisionFilter("", NULL_KEY, FALSE);</lsl>
<source lang="lsl2">llCollisionFilter("", NULL_KEY, FALSE);</source>
This script, placed in a wearable object, detects a collision when the person wearing it collides with an object named "Post":
* 1st instance :
an object named "Post" has several child prims named "Object" .
The prim named "Post" hits the scripted object or scripted prim , the collision will be detected
* 2nd instance :
an object named "Post" has several child prims named "Object" .
A child prim named "Object" hits the scripted object or scripted prim, the collision will be detected
* 3rd instance :
an object named "Object" has several child prims named "Post" .
A prim named "Post" hits the scripted object or scripted prim, the collision will not be detected


== Complete script whit llcollisionfilter ==
<source lang="lsl2">default
<lsl>
//The stair sound script. Make a sculpted oe prim stair make sound when an avatar go up on down on It.
//MathieuBC Noel scripter and freebie maker. Don't erase that part when you use this script
key    id  ; 
default
{
{
     state_entry()
     state_entry()
     {
     {
        llCollisionFilter("Post","",TRUE);
     }
     }
 
    collision_start(integer total_number)  //It's write colision start to notofy the computer that     
    collision_start(integer total_number)
                                            //the next command line are going to work when the       
                                            //object detect an colision.
    {   
        if (AGENT)                          //The computer star to read the command line when It's
                                            //an avatar colide on this.
          {
          llGetAgentInfo( id );            //Agent key is get by the object.
          llCollisionFilter("", id, TRUE);  //You have an colision only whit an agant whit the key                 
                                            //taken by the object.
          llSensorRepeat( "", id, AGENT, 3, PI,.7 ); //The sensor is sctivate each .7 second
            }
          else
            { 
              state off ;                    //If It's not an AGENT colision the computer must use   
                                              //the state off command line well below in the script
                                              //sheet.
              }
                }
              collision_end(integer total_number)
    {   
          llSensorRemove();                    //When the object did not detect an colision, the
                                                //sensor is remove
            }
            sensor(integer  total_number)      //This is the sensor action when It's activate whit
                                                //the above command line in the begin of this sheet.
    {
        if(AGENT_WALKING)                      //If the sensor detect in his radius an Agent
                                                //walking and running please dothe command line
                                                //below.
            llPlaySound("steps_on_wooden_stairs", 1.0);  //Play the sound name I put in the
                                                        //inventory object. You can also copy and 
                                                        //past the UUID of the soung between the two
                                                        //" .
        else                                            //Otherwise (else), if the agent do nothing
                                                        //read orther command line.
            llStopSound();                              //Stop sound
}
          land_collision_start(vector pos)              //If the object have an land colision follow
                                                        //the lines below.
{      llStopSound();                       
        llSensorRemove();                                //Remove the repeat sensor.
}
        }
      state off                                        //This is the state off apear in the beginig 
                                                        //of the script.                                 
{
    state_entry()
     {
     {
        llSay(0, "OUCH!");
    llStopSound();                                      //Stop sound                 
    llCollisionFilter("", id, FALSE);                   //Stop the filtering of collision identity 
                                                        //and UIID detection to choose to have and 
                                                        //colision whit It.
state default ;                                              //Retun to the begening of the script                                               
}
     }
     }
</lsl>
}</source>
|helpers
|helpers
|also_functions=
|also_functions=
Line 125: Line 60:
|permission
|permission
|cat1=Collision
|cat1=Collision
|cat2
|cat2=Legacy Name/As A Parameter
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 18:26, 21 May 2020

Summary

Function: llCollisionFilter( string name, key id, integer accept );
0.0 Forced Delay
10.0 Energy

Sets the collision filter, exclusively or inclusively.

• string name filter for specific object name or avatar legacy name
• key id filter by group, avatar or object UUID
• integer accept TRUE only process collisions that match, FALSE instead excludes matches

If accept == TRUE, only accept collisions with objects name AND id (either is optional), otherwise with objects not name AND id
If name or id are blank they are not used to filter incoming messages (or you could say they match everything). If id is an invalid key or a null key, it is considered blank.

Caveats

  • Any call of llCollisionFilter in the same event as llVolumeDetect changing (not just being called, but actually moving from FALSE to TRUE or vice versa) will be disregarded (before or after), if the event handler previously called a user-defined function. See #SVC-2490
  • Damage caused by llSetDamage will still apply to a filtered avatar.
    • Consequently, the object will immediately die on collision with the avatar. (And kill the avatar their health reaches 0.)

Examples

Stop filtering:

llCollisionFilter("", NULL_KEY, TRUE);

Filter out all collisions:

llCollisionFilter("", NULL_KEY, FALSE);

This script, placed in a wearable object, detects a collision when the person wearing it collides with an object named "Post":

  • 1st instance :

an object named "Post" has several child prims named "Object" . The prim named "Post" hits the scripted object or scripted prim , the collision will be detected

  • 2nd instance :

an object named "Post" has several child prims named "Object" . A child prim named "Object" hits the scripted object or scripted prim, the collision will be detected

  • 3rd instance :

an object named "Object" has several child prims named "Post" . A prim named "Post" hits the scripted object or scripted prim, the collision will not be detected

default
{
    state_entry()
    {
        llCollisionFilter("Post","",TRUE);
    }

    collision_start(integer total_number)
    {
        llSay(0, "OUCH!");
    }
}

See Also

Events

•  collision_start
•  collision
•  collision_end

Functions

•  llPassCollisions
•  llVolumeDetect

Deep Notes

Signature

function void llCollisionFilter( string name, key id, integer accept );