Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help please I'm almost there

Mako Davidson
Registered User
Join date: 27 Jun 2006
Posts: 56
06-20-2007 22:29
Hello there, I've nearly got this gun working how I would like it to, however I am trying to get the Dialogue box to stay open after each button press and can't figure it out. Would anyone please know where in the script and what syntax to use. Also I have been told that checking if the object is owned by the agent attaching it is probably not necessary and that an attach() event can be generated without that ownership. If so what part of the script does this refer to, what do I // or delete please and is there an alternative for Calling llDie() in the event of missed permissions which might be disappointing to anyone owning a no-copy instance of the gun. The 2 main scripts are listed below.

Thank you.


// switch this to ATTACH_LHAND if you are left-handed
integer gAttachPart = ATTACH_RHAND;
// this is a permission combination we check for many times
// I define it here so we don't have to keep typing it
// guns need to take controls, attach themselves, and possibly
// trigger animations
// NOTE: since I can't initialize to an expression (even if it is
// all constants), this moved to default { state_entry() }
integer gDesiredPerm;
// indicates whether wearer has yet given permission
integer gHavePermissions;
// Bullet travel speed
float gBulletSpeed = 30.0;
// when we last fired a shot
float gLastFireTime = 0;
// how long it takes to reload when tapping
float gTapReloadTime = 0.05;
// how long it takes to reload when holding
float gHoldReloadTime = 0.5;
// how long it takes when we're out of ammo
float gOutOfAmmoReloadTime = 1.5;
// how many shots before reload is necessary
integer gAmmoClipSize = 7;
// how much ammo we have right now
integer gAmmo;
string Bullet="blitz";
// HACK: how far away the eye is from the avatar's center (approximately)
vector gEyeOffset = <0.0, 0.0, 0.75>;
integer Handle1;
integer Handle2;
integer Handle3;

say(string msg)
{
llSay(0, msg);
}
debug(string msg)
{
// llSay(0, msg);
}
func_debug(string msg)
{
// llSay(0, msg);
}
// the gun has only one state
default
{
on_rez(integer start_param)
{
llListenRemove(Handle1);
llListenRemove(Handle2);
llListenRemove(Handle3);
Handle1 = llListen(0,"",llGetOwner(),"blitz";);
Handle2 = llListen(0,"",llGetOwner(),"orbit";);
Handle3 = llListen(0,"",llGetOwner(),"pull";);
gAmmo = gAmmoClipSize;
func_debug("on_rez";);
llOwnerSay("type '/- or /--' for 'holster/holster', 'bling on', 'bling off'";);
llPreloadSound("pistol_shot.wav";);
llPreloadSound("pistol_reload.wav";);
}

state_entry()
{
vector size = llGetAgentSize(llGetOwner());
gEyeOffset.z = gEyeOffset.z * (size.z / 2.0);
llListenRemove(Handle1);
llListenRemove(Handle2);
llListenRemove(Handle3);
Handle1 = llListen(0,"",llGetOwner(),"blitz";);
Handle2 = llListen(0,"",llGetOwner(),"orbit";);
Handle3 = llListen(0,"",llGetOwner(),"pull";);
func_debug("default state_entry";);
gHavePermissions = FALSE;
gDesiredPerm = (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
gAmmo = gAmmoClipSize;
llResetTime();
}

listen (integer channel, string name, key id, string message)
{
string temp_message = llToUpper(message);
integer strlong = llStringLength(message);
if(message=="blitz";)
{
Bullet="blitz";
llSay(0,"blitz enabled";);
llStopAnimation("gun hold";);
llStartAnimation("reload";);
llStartAnimation("gun hold";);
llTriggerSound("pistol_reload.wav", 1.0);
}

if(message=="orbit";)
{
Bullet="orbit";
llSay(0,"orbit enabled";);
llStopAnimation("gun hold";);
llStartAnimation("reload";);
llStartAnimation("gun hold";);
llTriggerSound("pistol_reload.wav", 1.0);
}

if(message=="pull";)
{
Bullet="pull";
llSay(0,"pull enabled";);
llStopAnimation("gun hold";);
llStartAnimation("reload";);
llStartAnimation("gun hold";);
llTriggerSound("pistol_reload.wav", 1.0);
}
}

link_message(integer sender, integer num, string str, key id)
{
if (str == "bb";)
{
Bullet = "blitz";
}

if (str == "ob";)
{
Bullet = "orbit";
}

if (str == "pb";)
{
Bullet = "pull";
}
}
// the player has touched us (left-clicked) // give directions
touch_start(integer tnum)
{
}
// Player attaches us, either by dragging onto self or from pie menu
attach(key av_key)
{
func_debug("attach";);

if (av_key != NULL_KEY)
{
// Can't attach if we don't own it
if ( av_key != llGetOwner() )
{
return;
}
// Always request permissions on attach, as we may be re-rezzing on login
llRequestPermissions(av_key, gDesiredPerm);
// run_time_permissions() is executed after this call
} else
{
func_debug(" detach";);

if ( gHavePermissions )
{
// we are being detached
llStopAnimation("gun hold";);
llReleaseControls();
llSetRot(<0.0, 0.0, 0.0, 1.0>;);
gHavePermissions = FALSE;
}
}
}
// this is called whenever llRequestPermissions() returns
// i.e. the user has responded or dismissed the dialog
// perm is the permissions we now have
run_time_permissions(integer perm)
{
func_debug("run_time_permissions";);
// see if we now have the permissions we need
if ( (perm & gDesiredPerm) == gDesiredPerm )
{
func_debug(" got perms";);
// we got the permissions we asked for
gHavePermissions = TRUE;
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("gun hold";);
} else
{
func_debug(" didn't get perms";);
// we didn't get them, kill ourselves
llDie();
}
}
// the player has used the controls, process them
control(key owner, integer level, integer edge)
{
func_debug("control";);
// has our gun reloaded?
float time = llGetTime();
// see if av has fired
// (edge & level) == down edges, (edge & !level) == up edges
// repeat rate is faster for tapping than holding
if ( ( ((edge & level) & CONTROL_ML_LBUTTON)
&& (time > gTapReloadTime) )
|| ( (time > gHoldReloadTime)
&& (level & CONTROL_ML_LBUTTON) ) )
{
// if player is out of ammo, must wait for reload
if ( (gAmmo >= 1) || (time > gOutOfAmmoReloadTime) )
{
// bang!
llTriggerSound("pistol_shot.wav", 1.0);
llResetTime();
// we fired, set timer back to 0
// HACK: gun shoots from gun pos, mouselook looks
// from player's eye, so we try to move the gun
// up to the eye. but we really don't
// know where it is, so we guess (see gEyeOffset)
vector my_pos = llGetPos() + gEyeOffset;
rotation my_rot = llGetRot();
vector my_fwd = llRot2Fwd(my_rot)*2.5;
// Rez a bullet!
llRezObject(Bullet,
my_pos+my_fwd,
my_fwd * gBulletSpeed,
my_rot,
0);
// decrease ammo count
--gAmmo;
if ( gAmmo > 0 )
{
// still bullets left
}
else if ( gAmmo == 0 )
{
// we just ran out of shots
// play reload sound here after a delay
llTriggerSound("pistol_reload.wav", 1.0);
llStartAnimation("reload";);
llSetTimerEvent(gOutOfAmmoReloadTime);
}
else // gAmmo < 0
{
// we've just fired first round of new clip
gAmmo = gAmmoClipSize - 1;
}
}
else
{
debug("Can't shoot, reloading...";);
}
}

} // control
timer()
{
gAmmo = gAmmoClipSize;
llSetTimerEvent(0);
}
} // default state
Mako Davidson
Registered User
Join date: 27 Jun 2006
Posts: 56
here's the other one
06-20-2007 22:30
key target;
integer lid;
float chann;
integer chan;
list List;
integer listener;
key owner;
default
{
state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
//llMessageLinked(LINK_SET,0,"bb",NULL_KEY);
}

on_rez(integer start_param)
{
List = [];
chan = (integer)llFrand(1000.0) + 1; // starts listening on a channel of 1 or higher up to 1000
owner = llGetOwner(); llListenRemove(listener); listener = llListen(chan,"",owner,"";);
llListen(chan,"",NULL_KEY,"";);
//llMessageLinked(LINK_SET,0,"bb",NULL_KEY);
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
}

touch_start(integer total_number)
{if ( llDetectedKey(0) == llGetOwner() )
{
target = llDetectedKey(total_number - 1);
llDialog(llDetectedKey(total_number - 1),"Deagle.50 Options",["Blitz", "Orbit","Pull" ], chan);
}
}

listen(integer channel, string name, key id, string message)
{
if (message == "Blitz";)
{
llMessageLinked(LINK_SET,0,"bb",NULL_KEY);
llSay(0,"blitz enabled";);
llStopAnimation("gun hold";);
llStartAnimation("reload";);
llStartAnimation("gun hold";);
llTriggerSound("pistol_reload.wav", 1.0);
//llMessageLinked(LINK_SET,0,"reload",NULL_KEY);
}

if (message == "Orbit";)
{
llMessageLinked(LINK_SET,0,"ob",NULL_KEY);
llSay(0,"orbit enabled";);
llStopAnimation("gun hold";);
llStartAnimation("reload";);
llStartAnimation("gun hold";);
llTriggerSound("pistol_reload.wav", 1.0);
//llMessageLinked(LINK_SET,0,"reload",NULL_KEY);
}

if (message == "Pull";)
{
llMessageLinked(LINK_SET,0,"pb",NULL_KEY);
llSay(0,"pull enabled";);
llStopAnimation("gun hold";);
llStartAnimation("reload";);
llStartAnimation("gun hold";);
llTriggerSound("pistol_reload.wav", 1.0);
//llMessageLinked(LINK_SET,0,"reload",NULL_KEY);
}
}
}
Mako Davidson
Registered User
Join date: 27 Jun 2006
Posts: 56
sorry typo
06-20-2007 22:32
Also I have been told that checking if the object is owned by the agent attaching it is probably not necessary and that an attach() event cant* be generated without that ownership.
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
06-21-2007 06:29
For your dialog question (which seems to involve the second script since thats the one with the dialog), put another call to the dialog within your listen event - as the last statement. That way, after you've done all your listen processing, the listen event will open the dialog again.
Mako Davidson
Registered User
Join date: 27 Jun 2006
Posts: 56
thanks RJ
06-21-2007 22:22
thanks a lot RJ it worked :)