Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

can anyone fix this script

Kidsin Dreadlow
Registered User
Join date: 27 Dec 2007
Posts: 11
08-07-2008 16:01
this is a script for the weapon on my tank.....it has no animations and doesnt attach to my arms...just how i like it...can anyone make it were it fires in mouselook....cause right now it only fires when the gun is touched...i need it to fire in mouse mode when i click the left mouse button


//
// Popgun
//
// This script is a basic gun- it waits for a mouseclick in mouselook and
// then fires a bullet in the direction the user is facing.
// It also animates the avatar holding it, to create a convining hold and
// firing look for the gun.
//
// This script can be used as a good basis for other weapons.
//

float SPEED = 20.0; // Speed of arrow in meters/sec
integer LIFETIME = 20; // How many seconds will bullets live
// before deleting themselves
float DELAY = 0.005; // Delay between shots to impose

vector vel; // Used to store velocity of arrow to be shot
vector pos; // Used to store position of arrow to be shot
rotation rot; // Used to store rotation of arrow to be shot

integer have_permissions = FALSE; // Indicates whether wearer has yet given permission
// to take over their controls and animation.

integer armed = TRUE; // Used to impose a short delay between firings

// Echoed to toucher if not worn


fire()
{
//
// This subroutine creates and fires an arrow
//
if (armed)
{
//
// Actually fires the arrow
//
armed = FALSE;
rot = llGetRot(); // Get current avatar mouselook direction
vel = llRot2Fwd(rot); // Convert rotation to a direction vector
pos = llGetPos(); // Get position of avatar to create arrow
pos = pos + vel; // Create arrow slightly in direction of travel
pos.z += 0.75; // Correct creation point upward to eye point
// from hips, so that in mouselook we see arrow
// travelling away from the camera.
vel = vel * SPEED; // Multiply normalized vector by speed

//llStartAnimation("shoot_R_handgun";); // Trigger the bow release animation
llTriggerSound("fire", 1.0); // Make the sound of the arrow being shot
llRezObject("Cannon Ball", pos, vel, rot, LIFETIME);
// Create the actual arrow from object
// inventory, and set its position, velocity,
// and rotation. Pass a parameter to it to
// tell it how long to live.

llSetTimerEvent(DELAY); // Wait until can fire again
}
}

default
{
state_entry()

{
}
on_rez(integer param)
{
//
// Called when the gun is created from inventory.
//

}

run_time_permissions(integer permissions)
{
//
// This routine is called when the user accepts the permissions request
// (sometimes this is automatic)
// so on receiving permissions, start animation and take controls.
//

}

attach(key attachedAgent)
{
//
// If attached/detached from agent, change behavior
//
if (attachedAgent != NULL_KEY)
{
// Bow has been attached or rezzed from inventory, so
// ask for needed permissions.
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
else
{
// Bow has been detached from avatar, so stop animation and release controls
if (have_permissions)
{
llStopAnimation("hold_R_handgun";);
llStopAnimation("aim_R_handgun";);
llReleaseControls();
llSetRot(<0,0,0,1>;);
have_permissions = FALSE;
}
}
}

touch_start(integer total_number)
{
fire();

}

touch_end(integer num)
{
// If touched, remind user how to enter mouselook and shoot

}

timer()
{
// After timer expires, allow user to shoot bow again
llSetTimerEvent(0.0);
armed = TRUE;
}

}
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
I don't think so.
08-08-2008 01:53
It's impossible to fire a canon, on leftclick, in mouselook, without having the canon atached to your avatar.

You can use a chatcommand to fire the thing, but then there would be no aiming.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
08-08-2008 13:13
i'm pretty sure that touch events are still received from mouse look. as for aiming, that would be a little more complicated, would probably need to use some sort of follow cam to know which direction you're looking so that the gun would adjust it's position/rotation accordingly
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
08-08-2008 13:24
You would need to use llTakeControls to take the left click command. Touch events only occur when you click on the object with the touch event, not when you click anywhere.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
08-08-2008 18:29
From: Yumi Murakami
You would need to use llTakeControls to take the left click command. Touch events only occur when you click on the object with the touch event, not when you click anywhere.


never used takecontrols, i assume it would either have to be attached, or you would need to be sitting on it, am i right? like i said, never used it before, so i have no idea

any object that i've bought that uses it, either is something i'm sitting on or wearing
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-08-2008 21:09
You can certainly take controls from a script in an object that is neither attached to the avatar nor has the avatar sitting on it. The target will just need to explicitly allow the PERMISSION_TAKE_CONTROLS from a blue dialog rather than it being granted automatically.
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
08-08-2008 21:43
You will also probably have to do some tricky maths to fire the cannon bullet at the thing the avatar is looking at (not merely in the same direction the avatar is looking, because since the cannon and the av aren't in the same place, that would miss)