Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need a Turret Script

Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
03-26-2006 14:15
Anyone got a turret script?
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-26-2006 16:45
Yup, here ya go :D. Please only use it inside battle sims though :D

CODE
key toucher;
float SPEED= 40.0;
vector vel;
vector pos;
rotation rot;
integer in_use;
string bullet="bullet";
fire()
{

rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.0;
vel = vel * SPEED;
llRezObject(bullet, pos, vel, rot, 1);
}
default
{
state_entry()
{
in_use = FALSE;
}
touch_start(integer total_number)
{
if(in_use == FALSE)
{
toucher = llDetectedKey(0);
llRequestPermissions(toucher, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
llSetText("Requesting Permissions", <1,1,1>, 1);
}
if(in_use == TRUE)
{
if(llDetectedKey(0) == toucher)
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
}
}
sensor(integer sense)
{
rotation k = llDetectedRot(0);
llRotLookAt(k, .1, .1);
}
no_sensor()
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
run_time_permissions(integer perm)
{
if(perm)
{
llSetText("", <1,1,1>, 1);
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llSensorRepeat("", toucher, AGENT, 20, TWO_PI, .1);
llSetText("Current User: "+llKey2Name(toucher), <1,1,1>, 1);
in_use = TRUE;
}
else
{
in_use = FALSE;
llSetText("", <1,3,1>, 1);
}
}
control(key name, integer levels, integer edges)
{
if ((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
{
fire();
}
}

}

Touch the script to have it start moving; you don't have to attach it to use. Then just go into mouselook and it will shoot where you want it to.
Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
03-27-2006 05:42
I meant a auto turret but that is a pretty cool script, thanks :D
Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
03-27-2006 11:08
Anyone got a auto turret script? I need one badly but all I can give you for it is 500l,
Burke Prefect
Cafe Owner, Superhero
Join date: 29 Oct 2004
Posts: 2,785
03-27-2006 12:34
Guess what, kids! You're buddy Burke is gonna hook you up!
I happen to be working on thisw very problem. An "HL1" style sentry turret for your combat needs.

Note: by "working on", I mean "no I won't give you a copy for free no matter how much you beg." If you look in the recent posts for Scripting Tips you'll see me asking for more help. :D
_____________________