Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

LLSetLinkAlpha, States and TakeControls...OH My!

Ilmira Yesheyev
Registered User
Join date: 8 Dec 2006
Posts: 40
12-27-2007 20:35
Howdy all. I'm having a rough time with some scripts and was hoping someone could point out what I am doing wrong. I am trying to script a belt and dagger and having some issues I can't figure out. When the dagger is drawn, the handle on the sheath should go transparent, but calls to LLSetLinkAlpha seem to be going in reverse 1.0 in making it tranparent instead of opaque and vice versa). Also, the sheath and dagger seem to be getting out of whack with the alpha. Sometimes they are both transparent, sometimes both visible and other times one is visible that should be invisible. I think I have got the controls worked out with the states like I need them, but if anyone can help me sort out the issues and make things work better, I'd be grateful. There are 3 scripts, the first goes in the root of the belt and is the main control sheathing and unsheathing the dagger. The second goes in child prims on the belt that are the dagger handle, and the third is the dagger script which is a picked apart and rearranged version of Cory Linden's sword script.

Belt control script
From: someone

integer sheathed;
default
{
on_rez(integer r)
{
llResetScript();
}

state_entry()
{
// llListen( 2, "", llGetOwner(), "" );
llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
sheathed = TRUE;
}

touch_start(integer total_number)
{
//integer status;
// status = sheathed;
if (sheathed)
{
// llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
llSay(-700448768,"draw";);
llMessageLinked(LINK_ALL_CHILDREN, 0, "draw", "" );
sheathed = FALSE;


}
else
{

//llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
llSay(-700448768,"sheath";);
llMessageLinked(LINK_ALL_CHILDREN, 0, "sheath", "" );
sheathed = TRUE;

}

}
// listen( integer channel, string name, key id, string message )
// {
//string msg = message;
// if (msg == "draw";)
//{
// llSay(-700448768,"sheath";);
// llMessageLinked(LINK_ALL_CHILDREN, 0, "draw", "" );
// sheathed = FALSE;


// }
// else
// {

//llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
//llSay(-700448768,"draw";);
//llMessageLinked(LINK_ALL_CHILDREN, 0, "sheath", "" );
// sheathed = TRUE;

// }

//}



}


Sheath alpha script
From: someone

default
{
state_entry()
{

}

link_message(integer Sender, integer Number, string Text, key ID)
{

string message = Text;
if(message == "draw";)
{
llSetLinkAlpha( LINK_THIS, 0.0, ALL_SIDES );
}
else
{

llSetLinkAlpha( LINK_THIS, 1.0, ALL_SIDES );
}

}
}


Dagger script
From: someone

integer SWORD = 1;
integer PUNCH12 = 2;
integer PUNCHL = 3;
integer KICK = 4;
integer FLIP = 5;
integer strike_type;

hide ()
{
llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
}

show()
{
llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
}

default
{
on_rez(integer r)
{
llResetScript();
}

state_entry()
{
llSetObjectDesc(llGetOwner());
llListen(-700448768, "", "", "" );
hide();


}
// attach(key id)
//{
// hide();

//}


listen( integer channel, string name, key id, string message )
{
string owner = llGetObjectDesc();
string msg = message;
if (owner == llGetOwner())
{
if(msg == "sheath";)
{
state sheath;


}
else{
if(msg == "draw";)
{

state drawn;






}

}
}
}



}
state drawn
{
state_entry()
{
llListen(-700448768, "", "", "" );
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
show();
integer perm = llGetPermissions();

if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
}
else
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
}
}
listen( integer channel, string name, key id, string message )
{
string owner = llGetObjectDesc();
string msg = message;
if (owner == llGetOwner())
{
if(msg == "sheath";)
{


state sheath;
}



}
}
run_time_permissions(integer perm)
{
if (perm)
{
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON | CONTROL_UP | CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT | CONTROL_DOWN, TRUE, TRUE);
}
}
timer()
{
if ( (strike_type == FLIP)
|| (strike_type == SWORD))
{
llSensor("", "", ACTIVE | AGENT, 4.0, PI_BY_TWO*0.5);
}
else
{
llSensor("", "", ACTIVE | AGENT, 3.0, PI_BY_TWO*0.5);
}
llSetTimerEvent(0.0);
}
control(key owner, integer level, integer edge)
{
if (level & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON))
{
if (edge & CONTROL_UP)
{
llApplyImpulse(<0,0,3.5>,FALSE);
llStartAnimation("backflip";);
llSetTimerEvent(0.25);
strike_type = FLIP;
}
if (edge & CONTROL_FWD)
{
llStartAnimation("sword_strike_R";);
llSleep(0.5);
llSetTimerEvent(0.25);
strike_type = SWORD;
}
if (edge & (CONTROL_LEFT | CONTROL_ROT_LEFT))
{
llStartAnimation("punch_L";);
llSetTimerEvent(0.25);
strike_type = PUNCHL;
}
if (edge & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
{
llStartAnimation("kick_roundhouse_R";);
llSetTimerEvent(0.25);
strike_type = KICK;
}
if (edge & CONTROL_BACK)
{
llStartAnimation("punch_onetwo";);
llSetTimerEvent(0.25);
strike_type = PUNCH12;
}
if (edge & CONTROL_DOWN)
{
llMoveToTarget(llGetPos(), 0.25);
llSleep(1.0);
llStopMoveToTarget();
}
}
}

sensor(integer tnum)
{
vector dir = llDetectedPos(0) - llGetPos();
dir.z = 0.0;
dir = llVecNorm(dir);
rotation rot = llGetRot();
if (strike_type == SWORD)
{
llTriggerSound("Sword - Impact08", 0.5);
dir += llRot2Up(rot);
dir *= 200.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCH12)
{
llTriggerSound("Sword - Impact08", 0.2);
dir += dir;
dir *= 100.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == PUNCHL)
{
llTriggerSound("Sword - Impact08", 0.2);
dir -= llRot2Left(rot);
dir *= 100.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == KICK)
{
llTriggerSound("Sword - Impact08", 0.2);
dir += dir;
dir *= 100.0;
llPushObject(llDetectedKey(0), dir, ZERO_VECTOR, FALSE);
}
else if (strike_type == FLIP)
{
llTriggerSound("Sword - Impact08", 0.2);
llPushObject(llDetectedKey(0), <0,0,150>, ZERO_VECTOR, FALSE);
}
strike_type= 0;
}


}

state sheath
{
state_entry()
{
hide();

state default;
}

}
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
12-27-2007 23:33
Just to clarify llSetAlpha and llSetLinkAlpha:

They define just how transparent an object is with 0.0 being not transparent and 1.0 being fully transparent.
Ilmira Yesheyev
Registered User
Join date: 8 Dec 2006
Posts: 40
12-27-2007 23:42
From: Squirrel Wood
Just to clarify llSetAlpha and llSetLinkAlpha:

They define just how transparent an object is with 0.0 being not transparent and 1.0 being fully transparent.



That's what I am using it for, to hide the prims based on whether the dagger is drawn or sheathed. So I guess the wiki is wrong in the description of the functions since it says 1.0 is opaque and 0.0 is fully transparent.
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
12-28-2007 02:57
From: Squirrel Wood
They define just how transparent an object is with 0.0 being not transparent and 1.0 being fully transparent.
This is incorrect. The script functions define how opaque an object it, exactly the opposite of the Transparency box on the Texture tab.
Ilmira Yesheyev
Registered User
Join date: 8 Dec 2006
Posts: 40
12-28-2007 10:12
That's what I thought, and it has worked correctly in other scripts. I just can't figure out where I am going wrong in these scripts t have it going all wonky. It's probably something simple, but I just cant see it. Hopefully someone will be able to pick them apart and find where I messed up.