Does anyone can hear the sound of the PlaySound function or only the player that use it?
Currently i’m creating a mod with a custom UI and i need to play a sound when the the UI opens and when it close.
Does anyone can hear the sound of the PlaySound function or only the player that use it?
Currently i’m creating a mod with a custom UI and i need to play a sound when the the UI opens and when it close.
If I remember well there is a variable in that function that let’s decide whether or not to play the file as 2D (audible from every position at max volume) or 3D (volume changes depending of position from which it is played).
The thing is that i want that only the person that opens the custom UI hear the opening/closing sounds of the UI. Is a custom book.
If I remember well the button UI’s have a sound variable - those should be audible by the “clicker” exclusively.
I know that, but i need to trigger the sound when the UI is visible, not when clicking an UI button.
Well then let’s work around it, eg: let’s make it that the UI pop up only after you press a button which has the sound coded in, or something like that. There’s always some way to work around this game’s limitations
Also - that kind of sound are we talking about exactly? One-off, or looping?
NOTE: I cannot recall if my own examples mentioned here limit to the reader only with respect to a MP game. If they do not, then assigning a sound within the XML as the button is clicked (EDIT: Or when the GUI is “opened” as you are asking) is the way to go I would have thought. (EDIT: I just checked my own examples, and they both play in the 20.0 meter diameter, and so would be heard by any player standing close to the player turning the pages. Which would be the case anyway, wouldn’t it? After all, I can hear my wife turning pages in her book. i.e. I don’t think the sound will impact any other player too much anyway.) Anyway …
Handling the PlaySound function has been particularly fiddly in my own experience, and I have even written a dedicated function to play one using that function because depending upon how it is called it will or will not play. All that aside, I also wrote a Readable Books GUI that you can check out that also has page turn sounds …
https://neverwintervault.org/project/nwn2/other/gui/readable-books-lb
When I have my module back for download (currently undergoing extensive SP testing by my wife and myself), I will re-release that for you to look at for examples too. Hopefully, within a few weeks at most.
EDIT (In case you wanted to know): The dedicated function calls for the nearest useable placeable object to play the sound. If no useable object is found within 20.0 (farthest the sound can be heard from), then it creates one to play the sound after a 0.2 second delay iirc, as it requires the delay in the case of a new object to be recognised before it can be played.
UPDATE: As the homebrew function in the Readable Books has changed since my latest rendition of it, I supply the updated homebrew function for you here (in case it helpful for you):-
NB: You would need to edit it for your own needs as you will not have all the supporting functions and variables, but this gives you the basic idea …
////////////////////////////////////////////////////////////////////////////////////////
// PLAY A SOUND WITHOUT INTERUPTING THE PC (GETAPLAYER USED) fDELAY IS DELAY (MIN 0.2)
// PLAYS SOUND IMMEDIATELY IF A USEABLE PLACEABLE NEARBY TO PLAY SOUND
////////////////////////////////////////////////////////////////////////////////////////
void LBPlaySound(string sSound, float fDelay = 0.5);
void LBPlaySound(string sSound, float fDelay = 0.5)
{
if(fDelay < 0.2){fDelay = 0.2;}
object oPC = GetAPlayer();
oPC = GetPCCurrentlyControlled(oPC);
object oMod = GetModule();
int iDMSOUND = GetLocalInt(oMod, "PLAYFORDM");
if(iDMSOUND == 1)
{
oPC = GetLocalObject(oMod, "THEDM");
DeleteLocalInt(oMod, "PLAYFORDM");
}
//SendMessageToPC(oPC, "HEARER PC IS >>> " + GetFirstName(oPC));
object oTEST = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, GetLocation(oPC));
float fDIS = GetDistanceBetween(oTEST, oPC);
//SendMessageToPC(oPlayer, ">>>> " + FloatToString(fDIS));
//if(GetDistanceBetween(oTEST, oPlayer) >= 20.0)
if(fDIS < 20.0)
{
if(GetUseableFlag(oTEST))
{
AssignCommand(oTEST, PlaySound(sSound, TRUE));
}
else
{
object oNEW = CreateObject(OBJECT_TYPE_PLACEABLE, "alb_temp_weather", GetLocation(oPC), FALSE, RandomName());
DelayCommand(fDelay, AssignCommand(oNEW, PlaySound(sSound, TRUE)));
DestroyObject(oNEW, fDelay + 3.0, FALSE);
}
}
else
{
object oNEW = CreateObject(OBJECT_TYPE_PLACEABLE, "alb_temp_weather", GetLocation(oPC), FALSE, RandomName());
DelayCommand(fDelay, AssignCommand(oNEW, PlaySound(sSound, TRUE)));
DestroyObject(oNEW, fDelay + 3.0, FALSE);
}
}
Thanks for the clarification of the function, i’m going to check what works for me. I know the mod that you mentioned, i used that and the GUI tutorial that you made to learn about how to create custom GUI for NWN2, i got inspired by the readable books mod for my GUI.
I’m currently working on some custom classes that use a different magic system.
They are nice! Well done!
I like the fact that you have moved the index/topic to a single left pane and (I assume) only update the second page. I considered something similar but wanted to keep the illusion of page turning, so ended up with the external index system (based on the conversation window).
I do also like the “background” images you have used. Your own design? Maybe they would be something you would be willing to share for some variety compared to the ones I currently use (Somebody else created those images too.)? At some point in the future anyway?
Nice work. If I can help, I will respond when I can.
Add a script call from the OnAdd section of the XML code.
Thanks, everything was made by myself except for the magic symbol in the bookmark and the book image which is a blank template that i picked from here.
The header and the footer image of the page(the one under the title and at the bottom of the page) are from the Tome of Magic book of D&D 3.5 which i copied and vectorized.
I just added anything that isn’t clickable or that isn’t text directly into the background image so, i would need to separate them first.
Yes, adding the sound in the OnAdd and in the OnRemove event should do the trick.
Good to know. (I have that D&D book as well, so I should be able to find those ones as well.)
I picked up the book image as well thanks! Always good to have some variations.
Yes, adding to the book background is the best way to do it if you can do so.
Thanks!