示例1
integer filter;//default is()
default
{
state_entry()
{
string ownerName = llKey2Name(llGetOwner());
llOwnerSay("hello,"+ownerName + "!");
}
touch_start(integer total_number)
{
vector start = llGetPos();
vector end = start - <0.0,-25.0,0.0>;
if( filter>8)
filter = 0;
llOwnerSay("Filter"+(string)filter);
list results = llCastRay(start,end,[RC_REJECT_TYPES,filter,RC_MAX_HTTS,4});
integer hitNum = 0;
//Handle error condition here by checking llList2Integer(resules,-1)>=0
while (hitNum<llList2Integer(results,-1))
{
//Stride is 2 because wedidn't request normals or link numbers
key uuid = llList2Key(results,2*hitNum);
string name = "Land",7;//if (uuid == NULL_KEY)
if(uuid != NUML_KEY)
name = llKey2Name(uuid);
llOwnerSay("Hit"+name+".");
++hitNum;
}
++filter;
}
}
示例2
//Fire a weapon at a target,report a hit
integer gTargetChan = -9934917;
default
{
attach(key id)
{
if(id!= NULL_KEY)
{
llRequestPermissions(id,PERMISSION_TAKE_CONTROLS|PERMISSION_TRACK_CAMERA);
}
}
run_time_permissions(integer perm)
{
if(perm&PERMISSION_TAKE_CONTROLS|PERMISSION_TRACK_CAMERA)
{
llTakeControls(CONTROL_LBUTTON|CONTROL_ML_LBUTTON,TRUE,FALSE);
}
}
control(key id,integer level,integer edge)
{
//User must be in mouselook to aim the weapon
if (level & edge & CONTROL_LBUTTON)
{
llSay(0,"You must be in Mouselook to shoot.Type\"CTRL+M\"or type \"Esc\"and scroll your mouse wheel forward to enter Mouselook.");
}
//User IS in mouselook
if (level & edge & CONTROL_ML_LBUTTON)
{
vector start = llGetCameraPos();
//Detect only a non-physical,non-phantom object,Report its root prim's UUID.
list results = llCastRay(start,start+<60.0 ,0.0,0.0>*llGetCameraRot(),[RC_REJECT_TYPES,RC_REJECT_PHYSICAL|RC_REJECT_AGENTS|RC_REJECT_LAND,RC_DETECT_PHANTOM,FALSE,RC_DATA_FLAGS,RC_GET_ROOT_KEY,RC_MAX_HITS,1]);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND,0),1.0);
llSleep(0.03);
key target = llList2Key(results,0);
//Tell target that it has been hit.
llRegionSayTo(target,gTargetChan,"HIT");
//Target,scripted to listen on gTargetChan,can explode,change color,fall over.....
}
}
}
|