De DigiWiki.
float damage = 100;
integer careAboutPrims = TRUE;
default
{
state_entry()
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
llListen(1231, "","","");
}
on_rez(integer a)
{
llResetScript();
}
run_time_permissions(integer permissions)
{
if (permissions == PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS)
{
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
}
}
listen(integer channel, string id, key idd, string message)
{
if(message == "careAboutPrim")
{
careAboutPrims = TRUE;
}
else
{
careAboutPrims = FALSE;
}
}
control(key name, integer levels, integer edges)
{
// This function is called when the mouse button or other controls
// are pressed, and the controls are being captured.
//
// Note the logical AND (single &) used - the levels and edges
// variables passed in are bitmasks, and must be checked with
// logical compare.
//
// Checking for both edge and level means that the button has just
// been pushed down, which is when we want to fire the arrow!
//
if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{
// If left mousebutton is pressed, fire arrow
rotation rot = llGetRot();
vector aim = llRot2Fwd(rot);
vector pos = llGetPos();
list results = llCastRay(pos, pos + aim * 15, [RC_REJECT_TYPES, 0]);
integer hitNum = 0;
// Handle error conditions here by checking llList2Integer(results, -1) >= 0
for ( hitNum = 0; hitNum < llList2Integer(results, -1); hitNum++ )
{
key uuid = llList2Key(results, 2*hitNum);
//llSay(0, uuid);
if(llGetOwner() != uuid && uuid != NULL_KEY)
{
if(careAboutPrims)
{
if(llGetAgentSize(uuid) == ZERO_VECTOR)
{
//llSay(0, "prim");
return;
}
}
osCauseDamage(uuid, damage);
}
}
}
}
attach(key attachedAgent)
{
//
// If attached/detached from agent, change behavior
//
if (attachedAgent != NULL_KEY)
{
// Bow has been attached or rezzed from inventory, so
// ask for needed permissions.
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
}
}