A few months back, I decided to write myself a flight booster script. I know there are free ones out there that work great, but I wanted the experience of writing my own. The flight functionality works perfectly, but it has one hitch that I can't figure out: When it switches states (in this case that also involves taking and releasing controls) it releases the controls for any other attachments I'm wearing as well, such as any sort of scripted weapon.
Given that there are freebie flight boosters out there that work just as well, I feel comfortable posting my work so people can analyze it. If anyone has any insight into what's causing my problem, please tell!
Also, I've never posted code before, so if this is ugly, I wouldn't mind some enlightenment there too

CODE
float power = 10.0;
default
{
state_entry()
{
llSetBuoyancy(0.0);
llSetTimerEvent(1.0);
llListen(0, "", llGetOwner(), "");
}
listen(integer channel, string name, key id, string msg)
{
if (llGetSubString(msg, 0, 2) == "fwf")
{
power = (float)llGetSubString(msg, 3, -1);
llOwnerSay("Power = " + (string)power);
}
}
attach(key attached)
{
if (attached != NULL_KEY)
{
llResetScript();
}
}
timer()
{
if(llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
{
//llOwnerSay("Flying");
state flying;
}
}
}
state flying
{
state_entry()
{
vector pos = llGetPos();
if((pos.z - llGround(<0,0,0>)) > 53)
{
llSetBuoyancy(1.0);
}
llSetTimerEvent(1.0);
llListen(0, "", llGetOwner(), "");
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
state_exit()
{
llReleaseControls();
}
listen(integer channel, string name, key id, string msg)
{
if (llGetSubString(msg, 0, 2) == "fwf")
{
power = (float)llGetSubString(msg, 3, -1);
llOwnerSay("Power = " + (string)power);
}
}
attach(key attached)
{
if(attached != NULL_KEY)
{
}
else
{
llReleaseControls();
}
}
timer()
{
if(llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
{
}
else
{
//llOwnerSay("Not Flying");
state default;
}
vector pos = llGetPos();
if((pos.z - llGround(<0,0,0>)) > 53)
{
llSetBuoyancy(1.0);
}
else
{
llSetBuoyancy(0.0);
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, TRUE);
}
}
control(key id, integer held, integer change)
{
if(held & CONTROL_UP)
{
llApplyImpulse(<0,0,power>, TRUE);
}
else if(held & CONTROL_DOWN)
{
llApplyImpulse(<0,0,-power>, TRUE);
}
else if(held & CONTROL_FWD)
{
llApplyImpulse(<power,0,0>, TRUE);
}
else if(held & CONTROL_BACK)
{
llApplyImpulse(<-power,0,0>, TRUE);
}
else if(held & CONTROL_RIGHT)
{
llApplyImpulse(<0,-power,0>, TRUE);
}
else if(held & CONTROL_LEFT)
{
llApplyImpulse(<0,power,0>, TRUE);
}
}
}