Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Mouseview Aiming Animation

Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
02-11-2009 16:01
Hey all,

I've got this script made by John Linden (Revolver Script) and I'm trying to pick out the section that tells your avatar to switch to an "aiming" animation when you switch to Mouseview. I'm trying to create my own gun - It's all pretty much done except I'm a bit stumped on this part. This is the only full-perm legit script I've found that uses this feature. (Idle gunholding animation, aiming animation when in mouselook). If anyone could help me pick out this section of the script I'd be VERY thankful! I've looked and looked and just can't seem to find it.

CODE

// Gun script
// John Linden

// where the gun attaches itself if you click on it
// switch this to ATTACH_LHAND if you are left-handed
integer gAttachPart = ATTACH_RHAND;

string INSTR_HELD_1 = "Enter Mouselook (press 'M') to shoot me.";
string INSTR_HELD_2 = "Right-click and choose 'Detach' to take me off.";

string INSTR_NOT_HELD_1 = "To wear and use me, right click and choose";
string INSTR_NOT_HELD_2 = "Acquire -> Attach -> Right Hand.";

string INSTR_NOT_OWNER_1 = "To use this gun, take it (right-click and choose 'Take'.)";
string INSTR_NOT_OWNER_2 = "Then, drag it from your inventory onto yourself.";

// this is a permission combination we check for many times
// I define it here so we don't have to keep typing it
// guns need to take controls, attach themselves, and possibly
// trigger animations
// NOTE: since I can't initialize to an expression (even if it is
// all constants), this moved to default { state_entry() }
integer gDesiredPerm;
// Indicates whether wearer has yet given permission
integer gHavePermissions;

// Bullet travel speed
float gBulletSpeed = 30.0;

// when we last fired a shot
float gLastFireTime = 0;
// how long it takes to reload when tapping
float gTapReloadTime = 0.05;
// how long it takes to reload when holding
float gHoldReloadTime = 1.0;
// how long it takes when we're out of ammo
float gOutOfAmmoReloadTime = 1.4;
// how many shots before reload is necessary
integer gAmmoClipSize = 6;
// how much ammo we have right now
integer gAmmo;

// HACK: how far away the eye is from the avatar's center (approximately)
vector gEyeOffset = <0.0, 0.0, 0.84>;


say(string msg)
{
llSay(0, msg);
}
debug(string msg)
{
// llSay(0, msg);
}
func_debug(string msg)
{
// llSay(0, msg);
}


// the gun has only one state

default
{
on_rez(integer start_param)
{
func_debug("on_rez");
// HACK: try to compensate for height of avatar
// by changing firing position appropriately
vector size = llGetAgentSize(llGetOwner());
gEyeOffset.z = gEyeOffset.z * (size.z / 2.0);

llWhisper(0,"Press 'M' to enter mouslook and the mouse button to fire");

// 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()
{
func_debug("default 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
| PERMISSION_TRIGGER_ANIMATION);
// Start with a full clip
gAmmo = gAmmoClipSize;
llResetTime();
}

// the player has touched us (left-clicked)
// give directions
touch_start(integer tnum)
{
func_debug("touch_start");

// Guns only work for their owner
if ( llDetectedKey(0) == llGetOwner() )
{
if ( gHavePermissions )
{
llWhisper(0, INSTR_HELD_1);
llWhisper(0, INSTR_HELD_2);
} else
{
llWhisper(0, INSTR_NOT_HELD_1);
llWhisper(0, INSTR_NOT_HELD_2);
}
} else
{
// Not the owner
llWhisper(0, INSTR_NOT_OWNER_1);
llWhisper(0, INSTR_NOT_OWNER_2);
}
}

// Player attaches us, either by dragging onto self or from pie menu
attach(key av_key)
{
func_debug("attach");

if (av_key != NULL_KEY)
{
// Can't attach if we don't own it
if ( av_key != llGetOwner() )
{
llWhisper(0, INSTR_NOT_OWNER_1);
llWhisper(0, INSTR_NOT_OWNER_2);
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
{
func_debug(" detach");

if ( gHavePermissions )
{
// we are being detached
llStopAnimation("hold_R_handgun");
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)
{
func_debug("run_time_permissions");

// see if we now have the permissions we need
if ( (perm & gDesiredPerm) == gDesiredPerm )
{
func_debug(" got perms");

// we got the permissions we asked for
gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_R_handgun");
} else
{
func_debug(" didn't get perms");

// we didn't get them, kill ourselves
llDie();
}
}


// the player has used the controls, process them
control(key owner, integer level, integer edge)
{
func_debug("control");

// 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 > gTapReloadTime) )
|| ( (time > gHoldReloadTime)
&& (level & CONTROL_ML_LBUTTON) ) )
{
// if player is out of ammo, must wait for reload
if ( (gAmmo >= 1) || (time > gOutOfAmmoReloadTime) )
{
// bang!
llTriggerSound("pistol_shot.wav", 1.0);
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 gEyeOffset)
vector my_pos = llGetPos() + gEyeOffset;
rotation my_rot = llGetRot();
vector my_fwd = llRot2Fwd(my_rot);

// Rez a bullet!
llRezObject("Bullet",
my_pos,
my_fwd * gBulletSpeed,
my_rot,
1);

// decrease ammo count
--gAmmo;
if ( gAmmo > 0 )
{
// still bullets left
}
else if ( gAmmo == 0 )
{
// we just ran out of shots
// play reload sound here after a delay
llTriggerSound("pistol_reload.wav", 1.0);
}
else // gAmmo < 0
{
// we've just fired first round of new clip
gAmmo = gAmmoClipSize - 1;
}
} else
{
debug("Can't shoot, reloading...");
}
}

} // control

} // default state


Any help is greatly appreciated!
Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
02-12-2009 01:50
Upon further inspection, the "default" hold_r_handgun animation seems like it automatically goes into "aiming" mode when you are in mouselook. I'm not exactly sure how I can replicate this using my own animations.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
02-12-2009 02:09
From: Nerolus Mosienko
Upon further inspection, the "default" hold_r_handgun animation seems like it automatically goes into "aiming" mode when you are in mouselook.

Yeah it does, that's a bit of magic built into the viewer.
From: someone
I'm not exactly sure how I can replicate this using my own animations.

You could use a timer or something to poll llGetAgentInfo() and see if AGENT_MOUSELOOK is set. Keep that in a variable and switch animations if it changes.
Tiffany Niles
Registered User
Join date: 14 Aug 2006
Posts: 9
my thoughts
02-12-2009 08:22
From: Nerolus Mosienko
Upon further inspection, the "default" hold_r_handgun animation seems like it automatically goes into "aiming" mode when you are in mouselook. I'm not exactly sure how I can replicate this using my own animations.



llStartAnimation("hold_R_handgun";);



if all you need to do is use your own animations here is where i would start by changeing the name of the animation here and anywhere else it is refrenced

might do what you need

tiff
Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
02-12-2009 08:57
Thank you both. I never knew that the animation automatically went into aiming mode!

The original script has

CODE

gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_R_handgun");


I can replace "hold_R_handgun" with my own animation, but then I'm stuck using ONE animation. I'll give setting a timer a try.
Thanks again!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-12-2009 10:58
Hmm. I wonder. If you named your holding animation "hold_R_sasquatch", would it automatically search for an animation called "aim_R_sasquatch"? I've never tried it.
Damet Neumann
Registered User
Join date: 21 Apr 2006
Posts: 140
may also notice this
02-12-2009 11:14
From: Nerolus Mosienko
Thank you both. I never knew that the animation automatically went into aiming mode!

The original script has

CODE

gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_R_handgun");


I can replace "hold_R_handgun" with my own animation, but then I'm stuck using ONE animation. I'll give setting a timer a try.
Thanks again!




llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_R_handgun";);



the only control it takes is the left mouse button in mouselook only thats why it doesnt fire unless you are in mouselook and why it only starts the animation once you are in mouselook
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
02-13-2009 20:19
From: Hewee Zetkin
Hmm. I wonder. If you named your holding animation "hold_R_sasquatch", would it automatically search for an animation called "aim_R_sasquatch"? I've never tried it.

It's hard coded into an if block that checks against constants for the rifle, handgun, bazooka and bow animations, so there isn't any pattern matching to ride on.

The interesting stuff is in here:
http://svn.secondlife.com/svn/linden/trunk/indra/newview/llagent.cpp

Grep in there for "mouselook-specific", there are two blocks of them, one for entering and one for leaving mouselook.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-14-2009 09:12
From: Viktoria Dovgal
It's hard coded into an if block that checks against constants for the rifle, handgun, bazooka and bow animations, so there isn't any pattern matching to ride on.

The interesting stuff is in here:
http://svn.secondlife.com/svn/linden/trunk/indra/newview/llagent.cpp

Grep in there for "mouselook-specific", there are two blocks of them, one for entering and one for leaving mouselook.

Ah. Okay. Oh well. It was a thought. Thanks for investigating.