Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Play sound on move script

Dan Colville
Registered User
Join date: 28 Jul 2006
Posts: 26
09-24-2008 01:29
This is a script what when an object moves a selected number of meters a sound will play. most of this stuff i don't know about so if you want to add comments just quote the script and add your own.

integer target_id;
vector target_pos;
string move = "87d359b2-838d-20e6-bab2-c7b483d413e0";

default
{
state_entry()
{
target_pos = llGetPos();
target_id = llTarget(target_pos, 0.5);//0.5 is the number of meters for this example //it's half a meter or 50cm
//define current avatar/prim position here
llTarget(llGetPos(), 0.1);
}
at_target(integer tnum, vector targetpos, vector ourpos)
{

if (tnum == target_id)
{
llStopSound();// action to be performed if the object is at the same position
}
}
not_at_target()
{llPlaySound(move, 5);// action to be preformed if object is not at the same position
llSleep(2.0); //Delays the script for two seconds you may not need it but i put it in for //myself
llTarget(llGetPos(), 0.1);}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Library bump
09-24-2008 05:19
:)
_____________________
i've got nothing. ;)
Tormented Twilight
#1 Cheese Lover
Join date: 30 Jan 2004
Posts: 103
10-10-2008 16:35
Perhaps this could be modified to play music when your avatar walks a set amount of distance. That way you could make a killer DigDug avatar that plays music when you run around ^_^
_____________________
SteamJunk, HoboJunk, SpaceJunk, FreeJunk n' more!
News, Online Store, Blog n' more: www.tinyurl.com/junkworld
Shop on XSL now: www.tinyurl.com/tormy
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
10-11-2008 11:20
I think you're going to want to use llTargetRemove() and set target_id each time you call llTarget(). Otherwise you'll remember some or all of your previous positions, and eventually cause an issue if there isn't a maximum on the number of targets set (not sure).

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llTarget
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llTargetRemove
Ava Velde
Registered User
Join date: 17 Jan 2009
Posts: 310
11-08-2009 13:25
thx
Vavaah Voom
Registered User
Join date: 19 Aug 2008
Posts: 1
play what kind of sound?
11-29-2009 00:49
I'd like to play music while I walk.. can't figure out how this script would modify to do that.. I just need to play one loop while I walk and doesn't matter about how far
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
11-29-2009 02:08
From: Vavaah Voom
I'd like to play music while I walk.. can't figure out how this script would modify to do that.. I just need to play one loop while I walk and doesn't matter about how far

Something like this I guess.
CODE

string gWalkSound = "900bdb8a-a208-1c9b-c08e-c67016bf3069";
integer gWalkControls;
integer gPlayingSound;
key gWearer;

GetPerms() {
if (llGetAttached())
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}

default
{
state_entry() {
gWalkControls = CONTROL_FWD|CONTROL_BACK|CONTROL_LEFT|CONTROL_RIGHT;
llMinEventDelay(0.25);
GetPerms();
}

on_rez(integer param) {
GetPerms();
}

attach(key id) {
GetPerms();
}

run_time_permissions(integer perm) {
if (perm & PERMISSION_TAKE_CONTROLS) {
llTakeControls(gWalkControls, TRUE, TRUE);
gWearer = llGetPermissionsKey();
}
}

control(key id, integer level, integer edge) {
integer playSound;
if (level & gWalkControls) {
playSound = llGetAgentInfo(gWearer) & AGENT_WALKING;
}
if (playSound) {
if (!gPlayingSound)
llLoopSound(gWalkSound, 1.0);
}
else if (gPlayingSound)
llStopSound();

gPlayingSound = playSound;
}
}