Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to script a weapon?

MystyReus Korobase
Registered User
Join date: 15 Jun 2008
Posts: 25
04-22-2009 13:05
I am building a weapon that needs to do the follwing:

Attach and appear / disappear to two different points on an avatar.
Animate that avatar when the item is visable and stop animating the avatar when the item is invisable.
The weapon needs to cause damage to another avatar when they are wearing a GLM meter.
The avatar needs to go into mouselook to use the weapon and the weapon needs to strike when someone left clicks.

So far, I have figured out the following:

How to get the item to appear and disappear using an alpha script(show /hide) that listesn for the words "draw lance and sheath lance".
How to animate the avatar but only at all times while it it attached ( I can not figure out how to get the animation to stop when it hears "sheath lance".

I have the animations I want to use, full perm. I have the damage script for GLM meters.

I want to give this weapon to everyone at an upcoming competetion for free so that the fighters are all using the same weapon.

*************** Some more details *****************

And thank you all for responding in the first place. I REALLY DO appreciate it, this is not easy and I am in way over my head.

The weapon is a lance and I would like it to act similar to the weapons available at Harbinger and Stormie. (Shameless plug for them! I love their stuff!)

So I bought a sword script, an alpha script, a damage script for the type of meter we will be using, an animation overide script and the animations I would like to use.

I built the lance/spear and made the parent prim the shaft. I made two copies, one that attaches to the spine of the avatar for when the lance is "Sheathed" and one that attaches to the right hand of the avatar for when the lance is "drawn."

So far, the item attached to the spine has an alpha script in it that makes the lance appear or disappear according to the chat command "draw lance" or "sheath lance" respectively. This item needs to tell the avatar to stand straight when the item is visable on the spine.

The item copy that attaches to the right hand also has an alpha script that causes the item to appear and disappear as well. This item also needs to animate the avatar to crouch when it is visable in the hand and stop animating when it is not visable. It also needs to allow the avatar to go into mouse-look and then allow the avatar to "strike" when the left mouse button is clicked.

My thoughts were...

Can I get each item to listen for the chat command "draw lance" and sheath lance" respectively so that the animation starts and stop as well??

And how? If it is some huge deal to get it to happen, then I need to have someone do it for me. Does that make sense? I'm using other peoples script and only barely know how to modify them...?

PS-SORRY IF YOU HAVE RESPONDED. I'M TRYING TO GET THIS POSTED IN THE RIGHT PLACE!!! :)
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
04-22-2009 16:44
To stop/start an animation, you can use the following functions:

llStartAnimation("Animation name here";);
llStopAnimation("Animation name here";);

Note that these functions require PERMISSION_TRIGGER_ANIMATION to be granted. You can have the script request the permission with the following function:

llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);


Good luck. ;)
_____________________
Life is a highway... And I just missed my exit.
Mojito Sorbet
Registered User
Join date: 12 Jun 2008
Posts: 13
Dont listen
04-22-2009 19:02
Listening to chat channel zero is inefficient. None of the pro weapons do that. Pick another channel and provide gestures to make it easy.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
04-22-2009 19:08
From: Cypher Ragu
To stop/start an animation, you can use the following functions:

llStartAnimation("Animation name here";);
llStopAnimation("Animation name here";);

Note that these functions require PERMISSION_TRIGGER_ANIMATION to be granted. You can have the script request the permission with the following function:

llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);


Good luck. ;)

Yep - also note that when somebody sits on something, SL autoplays the built-in 'sit' animation. You'll need to llStopAnimation("sit";) before starting your animation if you're doing poseballs.
MystyReus Korobase
Registered User
Join date: 15 Jun 2008
Posts: 25
Change between animations?
04-23-2009 09:27
Ok! thanks so much everyone for your help. I have the animations working, I have the visable and invisable working...

How do I get it to change between animations, like:

Avatar is at rest, no animation.
then forward and right click triggers a swing animation,
then arrow left and right click triggers a different swing animation,

etc.

would it look like this?



llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);

llStartAnimation("Animation name here";);

**** then what goes here?****

llStopAnimation("Animation name here";);

**** and what goes here?****

Gods! Who can I pay to do this??
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
04-23-2009 13:04
To do that, you'll want to take the user's controls. As with playing animations, taking controls requires permission from the user. The following function will request permissions to take controls:

llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);

Once you've got permissions, you can do this:

llTakeControls(CONTROL_FWD|CONTROL_BACK|CONTROL_ROT_LEFT|CONTROL_LEFT|CONTROL_ROT_RIGHT|CONTROL_RIGHT, TRUE, TRUE);

Doing this will allow the script to monitor the arrow keys.

Placing llStartAnimation or llStopAnimation in the control event should work. Part of it might look like this:

From: someone

control(key ID, integer Level, integer Edge)
{
if (Level & CONTROL_FWD)
{
//Play animation for moving foreward//
llStartAnimation("ForewardWalk";);
}
else
{
//The user isn't walking forewards, so stop the foreward walk animation//
llStopAnimation("ForewardWalk";);
}

if (Level & CONTROL_BACK)
{
//Play animation for moving backward//
llStartAnimation("BackwardWalk";);
}
else
{
//The user isn't walking backwards, so stop the backward walk animation//
llStopAnimation("BackwardWalk";);
}
}


...etc.


Hope this helps. ^_^
_____________________
Life is a highway... And I just missed my exit.