Aller au contenu

Photo

Soundninja script / PlaySound question


  • Veuillez vous connecter pour répondre
10 réponses à ce sujet

#1
kamal_

kamal_
  • Members
  • 5 260 messages
Is there a soundninja script out there? Mine doesn't work, though the ninja appears (in my testing, my ninja is not scripthidden). In my testing I've tried both a stock sound, and the actual sound I want (which I know works, as I have another way to play it), and my sound is turned up plenty loud enough.

Here is the script I'm using.

// ga_play_sound replacement, summons the "sound ninja" creature to play sounds since
// playsound goes at end of action queue, so an npc may not play immediately
// for more see http://nwn2.wikia.com/wiki/PlaySound

#include "ginc_param_const"

void main(string sSound, string sTarget, float fDelay)
{
object oTarget = GetTarget(sTarget, TARGET_OWNER);
location lTarget = GetLocation(oTarget);
object oSoundNinja;
oSoundNinja = CreateObject(OBJECT_TYPE_CREATURE, "sh_sound_ninja", lTarget);

if(GetIsObjectValid(oSoundNinja))
{
SendMessageToPC(GetFirstPC(), "Debug: sound ninja valid, playing sound");
AssignCommand(oSoundNinja, DelayCommand(fDelay,PlaySound(sSound)));
}
float fDestroyDelay = fDelay + 120.0; //high value for testing.
DelayCommand(fDestroyDelay, DestroyObject(oSoundNinja));
}

#2
kevL

kevL
  • Members
  • 4 075 messages
- played around with this for a few minutes:

Sounds like it needs a delayed wrapper function for the PlaySound() line. heck i'll just post what i got here

// 'kam_sound_ninja'

#include "ginc_param_const"


void kL_PlayNinja(string sSound, object oSoundNinja, float fDelay)
{
	DelayCommand(fDelay, AssignCommand(oSoundNinja, PlaySound(sSound)));

	fDelay += 10.f;
	DelayCommand(fDelay, DestroyObject(oSoundNinja));
}


// void main(string sSound, string sTarget, float fDelay)
void main()
{
	string sSound = "as_hr_x2ghost10";
	string sTarget = "c_mindflayer";
	float fDelay = 0.f;

	object oTarget = GetTarget(sTarget, TARGET_OWNER);
	location lTarget = GetLocation(oTarget);

	object oSoundNinja = CreateObject(OBJECT_TYPE_CREATURE, "kl_flayer_ninja", lTarget);

	if (GetIsObjectValid(oSoundNinja))
	{
		SendMessageToPC(GetFirstPC(), "Debug: sound ninja valid, playing sound");

		DelayCommand(0.1f, kL_PlayNinja(sSound, oSoundNinja, fDelay));
	}
}


#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
The way I handle it, I just paint down a one-shot sound in the area that's set to be non-positional, so that it plays the same no matter where the PC is. Then the script just has to trigger the sound.

I think the real problem you have is that the PlaySound function actually plays something quiet, like with only a 10m max radius. Since most players have the camera 10m from their PC, with the object in question a few meters in front of the PC, it's just difficult to hear.

Maybe you could copy the sound object to a particular location?

#4
kevL

kevL
  • Members
  • 4 075 messages
it's distinctly there with a delayed wrapper ... wasn't till that went in.

Not sure if i really like sound_ninjas though; i guess it's portable .....

#5
kamal_

kamal_
  • Members
  • 5 260 messages
Here's a working script, along with some commented notes

/*
  credit to kevL at http://social.biowar...800566#15801095

ga_play_sound replacement, summons the "sound ninja" creature to play sounds since playsound goes at end of action queue, so an npc may not play immediately for more see http://nwn2.wikia.com/wiki/PlaySound

Note that the sound ninja does not need to have any scripts on it at all, but "Disable AI while hidden" must not be checked.

Also note the string sSound is not the tag of a sound object, but the filename of the actual wav sound file to play

*/

#include "ginc_param_const"

void kL_PlayNinja(string sSound, object oSoundNinja, float fDelay)
{
DelayCommand(fDelay, AssignCommand(oSoundNinja, PlaySound(sSound)));
fDelay += 10.f;
DelayCommand(fDelay, DestroyObject(oSoundNinja));
}

void main(string sSound, string sTarget, float fDelay)
{
object oTarget = GetTarget(sTarget, TARGET_OWNER);
location lTarget = GetLocation(oTarget);
object oSoundNinja = CreateObject(OBJECT_TYPE_CREATURE, "sh_sound_ninja", lTarget);
if (GetIsObjectValid(oSoundNinja))
{
DelayCommand(0.1f, kL_PlayNinja(sSound, oSoundNinja, fDelay));
}
}

#6
kamal_

kamal_
  • Members
  • 5 260 messages
I discovered one reason my sounds were not playing was because I was passing the tag of the sound object I wanted, not the name of the wav file. kevL's hardcoded example was using the name of the wav, so it played. All of which is my bad for not being sufficiently caffeinated this morning when reading the wiki for playsound.

Modifié par kamal_, 05 février 2013 - 06:29 .


#7
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
BTW, kamal_, how are you handling sounds for your ambient musicians?

#8
kamal_

kamal_
  • Members
  • 5 260 messages

Lugaid of the Red Stripes wrote...

BTW, kamal_, how are you handling sounds for your ambient musicians?

I have "bard song" triggers. They're standard onenter/onexit triggers for playing/stopping a sound object, except they look for the musician's tags instead of the pc. Since the musicians dont wander around all day, only go home at night and go back to their spot in the morning, this works. The triggers aren't too large, to prevent the scripts from running constantly as npcs walk around. The sound objects for these triggers are songs.

//OnEnter
void main()
{

object oEnterer = GetEnteringObject();
object oSndPlayer = GetObjectByTag(GetLocalString(OBJECT_SELF,"sound_player"));

//sound only plays while npc is in trigger
if (GetTag(oEnterer)!= GetTag(oSndPlayer)) return;
object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF,"sound_tag"));
SoundObjectPlay(oTarget);

}

//OnExit
void main()
{

object oExiter = GetExitingObject();
object oSndPlayer = GetObjectByTag(GetLocalString(OBJECT_SELF,"sound_player"));

//sound only plays while npc is in trigger
if (GetTag(oExiter)!= GetTag(oSndPlayer)) return;
object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF,"sound_tag"));
SoundObjectStop(oTarget);

}

#9
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Ok, so you just use a random list of the canned sounds from the game? Before, when I tried it, I had set the frequency variation high enough that it almost sounded like chord changes, but even then the sounds got repetitive very quickly.

In tDU I placed single-shot sound objects, and then had the ambient script do a GetNearestObjectByTag and start the objects each heartbeat.

#10
kamal_

kamal_
  • Members
  • 5 260 messages

Lugaid of the Red Stripes wrote...

Ok, so you just use a random list of the canned sounds from the game? Before, when I tried it, I had set the frequency variation high enough that it almost sounded like chord changes, but even then the sounds got repetitive very quickly.

In tDU I placed single-shot sound objects, and then had the ambient script do a GetNearestObjectByTag and start the objects each heartbeat.

I'm using freely downloadable music that I've converted into the format nwn2 uses, so the bards play appropriate songs. I'm not using any stock sound or music for the environment in Crimmor.

Another 30 minutes or so and I'll have some ingame video uploaded showing the custom sound and bard music, as well as my commoner ai and the results of Apep's dynamic clothing equipping.

Modifié par kamal_, 06 février 2013 - 02:54 .


#11
kamal_

kamal_
  • Members
  • 5 260 messages
Here you go, a demo video showing bards playing music, commoners running their ai, etc as my test character wanders around.
www.youtube.com/watch

jamendo.com is great for custom music since all their music is creative commons licensed. last.fm has a free download section for music as well.