Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How To Stop Shells Rezzing Please

Candy Ferguson
Registered User
Join date: 22 Jun 2006
Posts: 20
01-03-2008 03:10
Below is a copy of my gun script that works well. All of the messages come from the gun HUD which also works well. My problem is that I have included a message to rez no shell (bullet casing) in cases where there is a lot of lag and the user wishes to disable that feature. I have cheated a bit here and included an object that is rezzed instead of the shell in this instance called no shell, which is actually an invisible shell that has a script in it that causes it to die on_rez. What I would prefer is not to have any shell object at all rez when the message no shell is broadcast from the HUD. Can someone please tell me how I could do this. I am actually not a very good scripter and this script has come about from a lot of visits to this forum and help from some extremely nice people :).

Thanking you muchly...

integer Handle1;
integer Handle2;
integer Handle3;
integer Handle4;
integer Handle5;
integer Handle6;
integer Handle7;
integer Handle8;
integer gAttachPart = ATTACH_RHAND;
integer gDesiredPerm;
integer gHavePermissions;
float gBulletSpeed = 30.0;
float gLastFireTime = 0;
float gTapReloadTime = 0.05;
float gHoldReloadTime = 0.5;
float gOutOfAmmoReloadTime = 3.5;
integer gAmmoClipSize = 20;
integer gAmmo;
string Bullet = "ap";
string Shell = "shell";
vector gEyeOffset = <0.0, 0.0, 0.75>;
vector gShellOffset = <0.0, 0.0, 1.10>;

default
{
on_rez(integer start_param)
{
llListenRemove(Handle1);
llListenRemove(Handle2);
llListenRemove(Handle3);
llListenRemove(Handle4);
llListenRemove(Handle5);
llListenRemove(Handle6);
llListenRemove(Handle7);
llListenRemove(Handle8);
Handle1 = llListen(-222,"","","ap";);
Handle2 = llListen(-222,"","","hv";);
Handle3 = llListen(-222,"","","td";);
Handle4 = llListen(-222,"","","rp";);
Handle5 = llListen(-222,"","","arm";);
Handle6 = llListen(-222,"","","disarm";);
Handle7 = llListen(-222,"","","shell";);
Handle8 = llListen(-222,"","","no shell";);
llOwnerSay("ARM, then Mouselook button to FIRE!!!, Left click gun/holster for bling";);
llPreloadSound("872db423-3353-12ab-c370-f9e18b69e1ec";);
llPreloadSound("41a71c65-4e9d-b7da-d6a3-db0d6151f946";);
llPreloadSound("88026413-b829-0df2-0e57-8212227a652c";);
llResetScript();
}

state_entry()
{
llListenRemove(Handle1);
llListenRemove(Handle2);
llListenRemove(Handle3);
llListenRemove(Handle4);
llListenRemove(Handle5);
llListenRemove(Handle6);
llListenRemove(Handle7);
llListenRemove(Handle8);
Handle1 = llListen(-222,"","","ap";);
Handle2 = llListen(-222,"","","hv";);
Handle3 = llListen(-222,"","","td";);
Handle4 = llListen(-222,"","","rp";);
Handle5 = llListen(-222,"","","arm";);
Handle6 = llListen(-222,"","","disarm";);
Handle7 = llListen(-222,"","","shell";);
Handle8 = llListen(-222,"","","no shell";);
vector size = llGetAgentSize(llGetOwner());
gEyeOffset.z = gEyeOffset.z * (size.z / 2.0);
gShellOffset.z = gShellOffset.z * (size.z / 2.0);
gAmmo = gAmmoClipSize;
llResetTime();
}

listen(integer channel, string name, key id, string message)
{
if( message == "ap" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Bullet = "ap";
llSay(0,"armour piercing round enabled";);
llStopAnimation("dual gun hold";);
llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
}
}
if( message == "hv" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Bullet = "hv";
llSay(0,"high velocity round enabled";);
llStopAnimation("dual gun hold";);
llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
}
}
if( message == "td" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Bullet = "td";
llSay(0,"taser dart round enabled";);
llStopAnimation("dual gun hold";);
llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
}
}
if( message == "rp" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Bullet = "rp";
llSay(0,"role play round enabled";);
llStopAnimation("dual gun hold";);
llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
}
}
if( message == "arm" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Bullet = "ap";
llSay(0,"armour piercing round enabled";);
//llStopAnimation("dual gun hold";);
//llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("1aca9dbc-9d71-2b01-9880-a2007e88dc63", 1.0);
}
}
if( message == "disarm" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
if (gHavePermissions)
{
llStopAnimation("dual gun hold";);
llTriggerSound("1aca9dbc-9d71-2b01-9880-a2007e88dc63", 1.0);
llReleaseControls();
gHavePermissions = FALSE;
}
}
}
if( message == "shell" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Shell = "shell";
llSay(0,"shell ejection enabled";);
llStopAnimation("dual gun hold";);
llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
}
}
if( message == "no shell" )
{
if ( llGetOwnerKey(id) == llGetOwner() )
{
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
llRequestPermissions(llGetOwner(), gDesiredPerm);
Shell = "no shell";
llSay(0,"shell ejection disabled";);
llStopAnimation("dual gun hold";);
llStartAnimation("gun reload";);
llStartAnimation("dual gun hold";);
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
}
}
}

attach(key av_key)
{
if (av_key != NULL_KEY)
{
llRequestPermissions(av_key, gDesiredPerm);
}
else
{
if (gHavePermissions)
{
llStopAnimation("dual gun hold";);
llReleaseControls();
llSetRot(<0.0, 0.0, 0.0, 1.0>;);
gHavePermissions = FALSE;
}
}
}

run_time_permissions(integer perm)
{
if ( (perm & gDesiredPerm) == gDesiredPerm )
{
gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("dual gun hold";);
}
}

control(key owner, integer level, integer edge)
{
float time = llGetTime();
if ( ( ((edge & level) & CONTROL_ML_LBUTTON)
&& (time > gTapReloadTime) )
|| ( (time > gHoldReloadTime)
&& (level & CONTROL_ML_LBUTTON) ) )
{
if ( (gAmmo >= 1) || (time > gOutOfAmmoReloadTime) )
{
llTriggerSound("88026413-b829-0df2-0e57-8212227a652c", 1.0);
llResetTime();
vector my_pos = llGetPos() + gEyeOffset;
vector my_pos2 = llGetPos() + gShellOffset;
rotation my_rot = llGetRot();
vector my_fwd = llRot2Fwd(my_rot)*2.5;
llMessageLinked(LINK_ALL_OTHERS, 0, "fire", NULL_KEY);
llRezObject(Bullet, my_pos+my_fwd, my_fwd * gBulletSpeed, my_rot, 0);
llRezObject(Shell, my_pos2, my_fwd * -1, my_rot, 0);
llRezObject(Shell, my_pos2, my_fwd * -1, my_rot, 0);
llRezObject(Shell, my_pos2, my_fwd * -1, my_rot, 0);

--gAmmo;
if ( gAmmo > 0 )
{
}
else if ( gAmmo == 0 )
{
llTriggerSound("872db423-3353-12ab-c370-f9e18b69e1ec", 1.0);
llStartAnimation("gun reload";);
llSetTimerEvent(gOutOfAmmoReloadTime);
llSleep(2);
}
else // gAmmo < 0
{
gAmmo = gAmmoClipSize - 1;
}
}
else
{
}
}
} // control

timer()
{
gAmmo = gAmmoClipSize;
llSetTimerEvent(0);
}
} // default state
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-03-2008 03:33
Firstly and most importantly you have to get rid of those listens. Remove ALL of the llListenRemove and llListen calls from the on_rez() event, and replace ALL the ones in the state_entry() event with the single line:

llListen(-222, "", NULL_KEY, "";);

There's no need to redo listens on_rez, as you're not cancelling them anywhere and they are persistent across rezzes - there's no need to have multiple listens on the same channel for multiple commands, since you check the command string - and there's no need to use llListenRemove at all.

Secondly, you have three shells ejecting at once, all in the same place. You don't need that surely. Replace the three llRezObject(Shell, my_pos2, my_fwd * -1, my_rot, 0); lines with the following if-clause, which only rezzes a shell when the Shell variable is not set to "no shell":

if (Shell != "no shell";) {
llRezObject(Shell, my_pos2, my_fwd * -1, my_rot, 0);
}
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Candy Ferguson
Registered User
Join date: 22 Jun 2006
Posts: 20
Thanks a lot Ordinal
01-04-2008 04:04
Thank you so much I did everything you said works a treat :)