Scripts / Playing Sound script

Author
Message
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 18th Jun 2016 09:59
Is it possible to make a script, wich plays a certain sound when f is pressed in the game?
And if yes, how ?
Saintyboy
9
Years of Service
User Offline
Joined: 18th Jun 2015
Playing:
Posted: 18th Jun 2016 14:57 Edited at: 18th Jun 2016 23:50
Sure is, make a script with following code and attach to an object that is set to always active with the sound you want to be played loaded into its soundfile slot in the object's properties :

Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 19th Jun 2016 19:12
hmm it doesnt work. I also had to change the script to this:

if g_KeyPressf then
PlaySound(e,0)
end


otherwhise i get an error message
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Jun 2016 19:31 Edited at: 19th Jun 2016 19:32
it should be double equals for lua (i would also change the PlaySound to PlaySoundIfSilent so that it wont do the annoying buzz if you hold f for any length of time)
Quote: "if g_KeyPressF == 1 then
PlaySoundIfSilent(e,0)
end"
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 19th Jun 2016 19:39
Error is because (=) instead of (==), it should looks like.....



Does you set the sound in properties, and/or fpe file?
Try some flag to be sure the code is running, something like a prompt.



If works, so maybe the sound is the issue, try the code with a well known sound (stock one), if works, so the code is not the problem, but the sound you are using for.

If you are using this piece of code with your own code, so try it out of your code, if it works and your audio works fine, so perhaps you are failing when merge it with your code.
And so on.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 19th Jun 2016 22:27
I have tried everythin you told me, it still doesnt work ;(

Northern
14
Years of Service
User Offline
Joined: 5th Nov 2010
Location: Brazil
Posted: 20th Jun 2016 08:39
Duchenkuke wrote:

Quote: "Is it possible to make a script, wich plays a certain sound when f is pressed in the game?
And if yes, how ?"


Yes, it is possible; not only one, but several sounds at the same time, if you want to, however, you need to be more specific about the kind of sound you want to play. For example:

1) Is it a long song or a sfx sound effect, such as an alarm, an explosion, voice sound, etc.

2) How many times do you want to play this sound? It's once, twice or continuously?

3) The sound will be played, when the player enters into a specific area or when approaching any object?

Therefore, if you do not define how do you plan to play a particular sound, it is difficult for people trying to help you.

Unfortunately, do not exist a generic solution, that works fine for all the cases, during a game play.

Good luck!
Northern
PM
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 20th Jun 2016 09:52 Edited at: 20th Jun 2016 09:53
okay So I am going to write down exactly what I want:

I am making a horror game, and I want to have a sound for the flashlight.

So, whenever I press f, there should be a short click sound. and when I spam f, there also should be the sound. literally everytime i active/deactivate the flashlight, it should make a sound. The sound itself is just 1 second long. I allready made it.

I hope you guys can help me and you find a solution for me xD

Thanks
Northern
14
Years of Service
User Offline
Joined: 5th Nov 2010
Location: Brazil
Posted: 20th Jun 2016 10:36
@Duchenkuke:

Thanks for clarifying a bit more about the sound event.

There will be specific places where you will turn the lantern on and off, or this event could happen in anywhere in the game level?

What does "...when I spam f, there also should be the sound..." mean?

Thanks,
Northern
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 20th Jun 2016 10:39
you just need to create a script to put the code above into but i've done it for you now and changed to non3D sound so the volume will stay constant.
assign script to any static = no, always active = yes object in the map and your sound effect in slot0.
a good guide for scripting in GG can be found in my signature.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 20th Jun 2016 10:49
Thank you so much, it worked !

Okay I will definitely check that guide out.
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 20th Jun 2016 18:52
I have one last request.....

In my game, there are notes that can be read, and I want them to make a noise everytime they get activated.
I short page sound just like in slender or similar games.
I am gonna be quiet after this one, I promise
But you Guys have that huge knowledge and I am wandering in darkness, even though there are guides and stuff..
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 20th Jun 2016 22:32
Couldn't find anything about audio... Or am I blind?
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 22nd Jun 2016 12:39 Edited at: 22nd Jun 2016 13:02
I just downloaded the script and looked through it. After trying it with this script i get error messages and when I paste the playsound command line in my instructions.lua it wont work either.

So I have tried everything in my power to get it to work. I'll check out the forums again.
Duchenkuke
GameGuru VBOTB Developer
8
Years of Service
User Offline
Joined: 7th Jun 2016
Location: Germany
Posted: 22nd Jun 2016 13:06
I DID IT ! FINALLY HAHA

AWW I DID SOMETHING ON MY OWN awesome xD

Login to post a reply

Server time is: 2024-12-22 18:22:28
Your offset time is: 2024-12-22 18:22:28