The problem is, the bullets don't act as expected. The first version did work though... on the wielder of the bracelet ! Hence the forward offest in the RezObject function.
Bracelet:
// Expel Gun script
integer gDesiredPerm;
// Indicates whether wearer has yet given permission
integer gHavePermissions;
// Bullet travel speed
float fairyvelocity = 32.0;
float timebetweenfairies = 0.05;
// how long it takes to reload when holding
float timebetweenmanyfairies = 1.0;
// HACK: how far away the eye is from the avatar's center (approximately)
vector eyedelta = <0.0, 0.0, 0.84>;
default
{
on_rez(integer start_param)
{
// HACK: try to compensate for height of avatar
// by changing firing position appropriately
vector size = llGetAgentSize(llGetOwner());
eyedelta.z = eyedelta.z * (size.z / 2.0);
// NOTE: can't do this if we want to attach by dragging from
// inventory onto the av, because the llResetScript(); clears
// all the callbacks, including attach()
// llResetScript();
// NOTE 2: This can be uncommented in 1.1 because you won't have
// to ask for permissions, you can just take them. But for now
// it pops up two dialog boxes if you drag onto the av, so I'll
// leave it out.
// Try to attach to the rezzer
// if ( !gHavePermissions )
// {
// llRequestPermissions(llGetOwner(), gDesiredPerm);
// }
}
state_entry()
{
gHavePermissions = FALSE;
// this should be initialized directly with the variable
// but I can't do that due to a bug
gDesiredPerm = (PERMISSION_TAKE_CONTROLS);
llResetTime();
}
// Player attaches us, either by dragging onto self or from pie menu
attach(key av_key)
{
if (av_key != NULL_KEY)
{
// Can't attach if we don't own it
if ( av_key != llGetOwner() )
return;
//
// Always request permissions on attach, as we may be re-rezzing on login
llRequestPermissions(av_key, gDesiredPerm);
// run_time_permissions() is executed after this call
} else
{
if ( gHavePermissions )
{
// we are being detached
llReleaseControls();
llSetRot(<0.0, 0.0, 0.0, 1.0>
;
gHavePermissions = FALSE;
}
}
}
// this is called whenever llRequestPermissions() returns
// i.e. the user has responded or dismissed the dialog
// perm is the permissions we now have
run_time_permissions(integer perm)
{
// see if we now have the permissions we need
if ( (perm & gDesiredPerm) == gDesiredPerm )
{
// we got the permissions we asked for
gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
} else
{
llWhisper(0, "Didn't get permissions..."
;
}
}
// the player has used the controls, process them
control(key owner, integer level, integer edge)
{
// has our gun reloaded?
float time = llGetTime();
// see if av has fired
// (edge & level) == down edges, (edge & !level) == up edges
// repeat rate is faster for tapping than holding
if ( ( ((edge & level) & CONTROL_ML_LBUTTON)
&& (time > timebetweenfairies) )
|| ( (time > timebetweenmanyfairies)
&& (level & CONTROL_ML_LBUTTON) ) )
{
llResetTime(); // we fired, set timer back to 0
// HACK: gun shoots from gun pos, mouselook looks
// from player's eye, so we try to move the gun
// up to the eye. but we really don't
// know where it is, so we guess (see eyedelta)
vector my_pos = llGetPos() + eyedelta;
rotation my_rot = llGetRot();
vector my_fwd = llRot2Fwd(my_rot);
// Rez a bullet!
llRezObject("Expel Bullet",
(my_pos + 5 * my_fwd),
my_fwd * fairyvelocity,
my_rot,
1);
}
} // control
} // default state
integer gDesiredPerm;
// Indicates whether wearer has yet given permission
integer gHavePermissions;
// Bullet travel speed
float fairyvelocity = 32.0;
float timebetweenfairies = 0.05;
// how long it takes to reload when holding
float timebetweenmanyfairies = 1.0;
// HACK: how far away the eye is from the avatar's center (approximately)
vector eyedelta = <0.0, 0.0, 0.84>;
default
{
on_rez(integer start_param)
{
// HACK: try to compensate for height of avatar
// by changing firing position appropriately
vector size = llGetAgentSize(llGetOwner());
eyedelta.z = eyedelta.z * (size.z / 2.0);
// NOTE: can't do this if we want to attach by dragging from
// inventory onto the av, because the llResetScript(); clears
// all the callbacks, including attach()
// llResetScript();
// NOTE 2: This can be uncommented in 1.1 because you won't have
// to ask for permissions, you can just take them. But for now
// it pops up two dialog boxes if you drag onto the av, so I'll
// leave it out.
// Try to attach to the rezzer
// if ( !gHavePermissions )
// {
// llRequestPermissions(llGetOwner(), gDesiredPerm);
// }
}
state_entry()
{
gHavePermissions = FALSE;
// this should be initialized directly with the variable
// but I can't do that due to a bug
gDesiredPerm = (PERMISSION_TAKE_CONTROLS);
llResetTime();
}
// Player attaches us, either by dragging onto self or from pie menu
attach(key av_key)
{
if (av_key != NULL_KEY)
{
// Can't attach if we don't own it
if ( av_key != llGetOwner() )
return;
//
// Always request permissions on attach, as we may be re-rezzing on login
llRequestPermissions(av_key, gDesiredPerm);
// run_time_permissions() is executed after this call
} else
{
if ( gHavePermissions )
{
// we are being detached
llReleaseControls();
llSetRot(<0.0, 0.0, 0.0, 1.0>

gHavePermissions = FALSE;
}
}
}
// this is called whenever llRequestPermissions() returns
// i.e. the user has responded or dismissed the dialog
// perm is the permissions we now have
run_time_permissions(integer perm)
{
// see if we now have the permissions we need
if ( (perm & gDesiredPerm) == gDesiredPerm )
{
// we got the permissions we asked for
gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
} else
{
llWhisper(0, "Didn't get permissions..."

}
}
// the player has used the controls, process them
control(key owner, integer level, integer edge)
{
// has our gun reloaded?
float time = llGetTime();
// see if av has fired
// (edge & level) == down edges, (edge & !level) == up edges
// repeat rate is faster for tapping than holding
if ( ( ((edge & level) & CONTROL_ML_LBUTTON)
&& (time > timebetweenfairies) )
|| ( (time > timebetweenmanyfairies)
&& (level & CONTROL_ML_LBUTTON) ) )
{
llResetTime(); // we fired, set timer back to 0
// HACK: gun shoots from gun pos, mouselook looks
// from player's eye, so we try to move the gun
// up to the eye. but we really don't
// know where it is, so we guess (see eyedelta)
vector my_pos = llGetPos() + eyedelta;
rotation my_rot = llGetRot();
vector my_fwd = llRot2Fwd(my_rot);
// Rez a bullet!
llRezObject("Expel Bullet",
(my_pos + 5 * my_fwd),
my_fwd * fairyvelocity,
my_rot,
1);
}
} // control
} // default state
And the bullets, spheres with a radius of 0.1:
integer flying = FALSE;
default
{
on_rez(integer sparam)
{
llSetStatus(STATUS_DIE_AT_EDGE, TRUE);
llSetBuoyancy(1.0);
if (sparam)
{
flying = TRUE;
}
llVolumeDetect(TRUE);
}
collision_start(integer total_number)
{
if (flying)
{
integer type = llDetectedType(0);
if (type & AGENT)
{
llTeleportAgentHome(llDetectedKey(0));
//llEjectFromLand(llDetectedKey(0));
}
llDie();
}
}
land_collision_start(vector pos)
{
if (flying)
{
llDie();
}
}
}
I gave one to the owner of the land I was on and had him shoot at me, and though the bullets were hitting me and pushing me slightly I wasn't teleported home. What am I doing wrong ? The bullets are set as Physics and Phantom.