Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help: Gun Hold/Aim animations

Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
09-24-2006 10:08
Hello,

Recently I made a shotgun, mainly for looks. I've tweaked a couple scripts to get it to fit the gun. It's a pump action shotgun, fires buckshot which bursts into a cloud of smoke on impact and ejects a shell.

I have this gun all figured out, except one thing...how do I change the default Hold/Aim animations? I have two animations bought and ready to be used for the gun. An aiming and standing animation. I've replaced the names of a few different animations in the script, but I always end up with my avatar stuck in my aiming animation, so I switched back to the default until I've found out how to correctly replace said animations. Here is the script:




//
// Semi Auto Script
//

float SPEED = 75.0;
integer LIFETIME = 10;

float DELAY = 0.2;

vector vel;
vector pos;
rotation rot;

integer have_permissions = FALSE;
integer armed = TRUE;
string instruction_not_held =
"Choose 'Acquire->attach->left hand' from my menu to wear and use me.";


fire()
{
if (armed)
{
armed = FALSE;
rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.75;


vel = vel * SPEED;


llTriggerSound("Report", 1.0);
llRezObject("Bullet", pos, vel, rot, LIFETIME);

rot.z = rot.z *-PI ;
llRezObject("Shotgun Shell",pos+<-0.0,-0.0,-0.0>,-llRot2Left(rot),rot,0);


llSetTimerEvent(DELAY);
}
}

default
{
state_entry()

{
if (!have_permissions)
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
}
on_rez(integer param)
{

llPreloadSound("Report";);
}

run_time_permissions(integer permissions)
{

if (permissions == PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS)
{

llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_R_rifle";);
have_permissions = TRUE;
}
}

attach(key attachedAgent)
{

if (attachedAgent != NULL_KEY)
{

llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
else
{

if (have_permissions)
{
llStopAnimation("hold_R_rifle";);
llStopAnimation("aim_R_rifle";);
llReleaseControls();
llSetRot(<0,0,0,1>;);
have_permissions = FALSE;
}
}
}

control(key name, integer levels, integer edges)
{

if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&;((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{

fire();
}
}

touch_end(integer num)
{

if (have_permissions)
{
; }
else
{
llWhisper(0, instruction_not_held);
}
}

timer()
{

llSetTimerEvent(0.0);
armed = TRUE;
}

}






Any help is GREATLY appreciated! I've searched everwhere but I've found nothing.


Thanks!
Nerolus Mosienko

(ps. I've made a version of the gun to be holstered on my back, if anyone could point me to a holster/unholster script, that would be VERY cool)
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
09-24-2006 11:22
The hold/aim anim change isn't in the script, it's in the animation itself. I don't know anims so you're best bet is prolly the Animations forum section. The two poses need to be put into the same anim somehow (that's done outside SL when the anim is made), and you just start the one anim when the gun is attached. SL will automatically change to the aim part of the anim when you go into mouselook.
_____________________
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
09-24-2006 12:01
Yeah, the above is the case. Using the "hold_r_(whatever)" animations automatically means the avatar goes to the "aim_r_(whatever)" animation when they go into mouselook, it's a sort of bonus for using the defaults.

If you want to have it put you into a different custom animation in mouselook, you have to use a timer to check whether you're in mouselook or not. (This is a really basic AO.) Here's a skeleton script to get you started:

CODE

string gHoldAnim = "my hold animation";
string gAimAnim = "my aim animation";
integer gControls = CONTROL_ML_LBUTTON;
integer gMouselook = FALSE;

default
{
attach(key id)
{
if (id == NULL_KEY) {
llStopAnimation(gHoldAnim);
llStopAnimation(gAimAnim);
llReleaseControls();
llSetTimerEvent(0.0);
}
else if (id == llGetOwner()) {
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}

run_time_permissions(integer perms)
{
llOwnerSay("Taking controls and starting animations");
llStartAnimation(gHoldAnim);
llSetTimerEvent(0.5);
llTakeControls(gControls, TRUE, FALSE);
}

timer()
{
integer mouselook = llGetAgentInfo(llGetOwner()) & AGENT_MOUSELOOK;
if (mouselook && !gMouselook) {
// entered mouselook
llStopAnimation(gHoldAnim);
llStartAnimation(gAimAnim);
gMouselook = mouselook;
}
else if (!mouselook && gMouselook) {
// left mouselook
llStopAnimation(gAimAnim);
llStartAnimation(gHoldAnim);
gMouselook = mouselook;
}
}
}

N.B. posting code using PHP tags is the best way to go.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-25-2006 11:01
From: Ordinal Malaprop
Yeah, the above is the case. Using the "hold_r_(whatever)" animations automatically means the avatar goes to the "aim_r_(whatever)" animation when they go into mouselook, it's a sort of bonus for using the defaults.

Dang! Really? I've been using a timer for that. I had no idea it was done automatically. LOL.
Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
09-26-2006 04:03
Ok, being a (or nearly) complete newb to script, I edited the Semi Auto script and put the timer inside of it, trying to merge the two together. Well I failed. The first time I tried to use the gun after I merged the two together it worked PERFECTLY for one shot. I wore the gun, animations worked fine both standing and aiming, and it shot just like I hoped. I clicked again to fire another shot...nothing. So I dropped it on the ground, tried wearing it again, same thing. I put it back in my inventory and tried wearing it from there, now it wont shoot at all, but the animation timer works fine. Here's what I've got:

CODE

//
// Semi Auto Script
//

float SPEED = 75.0;
integer LIFETIME = 10;

float DELAY = 0.2;

vector vel;
vector pos;
rotation rot;

string gHoldAnim = "Ape_Stand09";
string gAimAnim = "GraveM_Stand06";
integer gControls = CONTROL_ML_LBUTTON;
integer gMouselook = FALSE;
integer have_permissions = FALSE;
integer armed = TRUE;
string instruction_not_held =
"Choose 'Acquire->attach->left hand' from my menu to wear and use me.";


fire()
{
if (armed)
{
armed = FALSE;
rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.75;


vel = vel * SPEED;


llTriggerSound("Report", 1.0);
llRezObject("Bullet", pos, vel, rot, LIFETIME);

rot.z = rot.z *-PI ;
llRezObject("Shotgun Shell",pos+<-0.0,-0.0,-0.0>,-llRot2Left(rot),rot,0);


llSetTimerEvent(DELAY);
}
}

default
{
state_entry()

{
if (!have_permissions)
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
}
on_rez(integer param)
{

llPreloadSound("Report");
}

control(key name, integer levels, integer edges)
{

if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{

fire();
}
}

touch_end(integer num)
{

if (have_permissions)
{
; }
else
{
llWhisper(0, instruction_not_held);
}
}

timer()
{

llSetTimerEvent(0.0);
armed = TRUE;
}

attach(key id)
{
if (id == NULL_KEY) {
llStopAnimation(gHoldAnim);
llStopAnimation(gAimAnim);
llReleaseControls();
llSetTimerEvent(0.0);
}
else if (id == llGetOwner()) {
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}

run_time_permissions(integer perms)
{
llStartAnimation(gHoldAnim);
llSetTimerEvent(0.5);
llTakeControls(gControls, TRUE, FALSE);
}

timer()
{
integer mouselook = llGetAgentInfo(llGetOwner()) & AGENT_MOUSELOOK;
if (mouselook && !gMouselook) {
// entered mouselook
llStopAnimation(gHoldAnim);
llStartAnimation(gAimAnim);
gMouselook = mouselook;
}
else if (!mouselook && gMouselook) {
// left mouselook
llStopAnimation(gAimAnim);
llStartAnimation(gHoldAnim);
gMouselook = mouselook;
}
}
}


Any more help is greatly appreciated!
Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
09-28-2006 22:48
Bump-still borked :(
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-29-2006 06:38
Okay I am new to scripting also. One thing that is invaluable and that lets you "look under the hood" of the script while it is running is to use llOwnerSay. Also either Scite-EZ or Notepad++ plus LSint are worth thier weight in gold. You can find links for them in the scipting wiki under "alternative editers".

I am getting a "Multiple handlers for event `timer' - only the last will execute."
Try running it like this and see where it is hanging at:

CODE

//
// Semi Auto Script
//

float SPEED = 75.0;
integer LIFETIME = 10;

float DELAY = 0.2;

vector vel;
vector pos;
rotation rot;

string gHoldAnim = "Ape_Stand09";
string gAimAnim = "GraveM_Stand06";
integer gControls = CONTROL_ML_LBUTTON;
integer gMouselook = FALSE;
integer have_permissions = FALSE;
integer armed = TRUE;
string instruction_not_held =
"Choose 'Acquire->attach->left hand' from my menu to wear and use me.";


fire()
{
if (armed)
{
armed = FALSE;
rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.75;


vel = vel * SPEED;


llTriggerSound("Report", 1.0);
llRezObject("Bullet", pos, vel, rot, LIFETIME);

rot.z = rot.z *-PI ;
llRezObject("Shotgun Shell",pos+<-0.0,-0.0,-0.0>,-llRot2Left(rot),rot,0);

llOwnerSay("fire_if");

llSetTimerEvent(DELAY);
}
}

default
{
state_entry()

{
if (!have_permissions)
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
llOwnerSay("if_perms");
}
}
on_rez(integer param)
{

llPreloadSound("Report");
llOwnerSay("preload_sound");
}

control(key name, integer levels, integer edges)
{

if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{

fire();
llOwnerSay("control_fire");
}
}

touch_end(integer num)
{

if (have_permissions)
{
;
llOwnerSay("touch_if;");
}
else
{
llWhisper(0, instruction_not_held);
llOwnerSay("touch_else");
}
}

timer()
{

llSetTimerEvent(0.0);
armed = TRUE;
llOwnerSay("timer_armed");
}

attach(key id)
{
if (id == NULL_KEY) {
llStopAnimation(gHoldAnim);
llStopAnimation(gAimAnim);
llReleaseControls();
llSetTimerEvent(0.0);
llOwnerSay("attach_if");
}
else if (id == llGetOwner()) {
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
llOwnerSay("attach_else");
}
}

run_time_permissions(integer perms)
{
llStartAnimation(gHoldAnim);
llSetTimerEvent(0.5);
llTakeControls(gControls, TRUE, FALSE);
llOwnerSay("run_time");
}

timer()
{
integer mouselook = llGetAgentInfo(llGetOwner()) & AGENT_MOUSELOOK;
if (mouselook && !gMouselook) {
// entered mouselook
llStopAnimation(gHoldAnim);
llStartAnimation(gAimAnim);
gMouselook = mouselook;
llOwnerSay("timer_if");
}
else if (!mouselook && gMouselook) {
// left mouselook
llStopAnimation(gAimAnim);
llStartAnimation(gHoldAnim);
gMouselook = mouselook;
llOwnerSay("timer_else");
}
}
}


Look in the sticky at top of Scripting Tips to see how to use the PHP tags for posted code here
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum