Here are some example scripts to get you going.
For your basketball:
default {
collision_start(integer numColliders) {
integer i;
for (i = 0; i < numColliders; ++i) { // For every collider...
if (llDetectedType(i) & AGENT) { // If its an AGENT (avatar)
llSay(0, "Sorry!");
}
}
}
}
Because attachments are phantom (non-collidable objects), they will not trigger a collision event in the hit object when they appear to hit the object. Instead, your sword should shout a message on a private
chat channel when it detects that it interpenitrates the object. The box should then listen on that channel, and react to the message.
For the sword:
integer COLLISION_CHANNEL = 19484;
default {
state_entry() {
llVolumeDetect(TRUE); // So the attachment can detect collision with the box.
}
collision_start(integer totalNumber) {
integer i;
for (i = 0; i < totalNumber; ++i) {
llShout(COLLISION_CHANNEL, (string)llDetectedKey(i));
}
}
}
For the box:
integer COLLISION_CHANNEL = 19484;
default {
on_rez(integer totalNum) {
llResetScript();
}
state_entry() {
llListen(COLLISION_CHANNEL, "", NULL_KEY, (string) llGetKey());
}
listen(integer channel, string name, key id, string message) {
llSay(0, "Ouch!");
}
}
You might have trouble with the sword. Animations are client side effects, so when you play an animation of your avatar swinging the sword at something, the "actual" sword might not be how it appears on your client. Im not exactly sure how llVolumeDetect works when in an attachment (Ive forgotten the results of my past tests on it) so you might need to use a
sensor instead.
==Chris