![]() |
How can I add a sound effect to my level with AS?
I'm trying to trigger a sound when the player walks into a certain tile. On the tile is a trigger zone event and I would like to trigger the sound COMMON_ITEMTRE when the players walks through the trigger zone, but only that particular trigger zone ID. I'm a noob with AS and programming in general, I tried to understand the AS readme, searched some threads, checked some code snippets from this site and looked how other users use AS in their levels but I still don't get it to work. I made the sugar rush counter code snippet from Bloody Body work with AS though so if I know the code I can do it.
Thank you very much in advance! |
This sounds like a perfect use case for an onFunction# hook, like
Code:
void onFunction0(jjPLAYER@ player) {Code:
void onFunction0(jjPLAYER@ player, uint8 triggerID) { |
Thank you a lot!! I will try this code now. I wonder why you have to write player.xPos and player.yPos though. Seems irrelevant to me, what am I missing?
I just tried it but I don't hear the sound yet. To be extra clear about what I try: When Jazz (or another) walks through the event 'Trigger Zone 21 | onoff 1 | switch 0' the sound COMMON_ITEMTRE has to be played. But only the first time he walks through it, I don't want the sound to trigger every time, only when the thing is triggered the first time. But I think that would be the case automatically anyways? I just copy/pasted the first code you send in my AS file where the other AS code already worked. And replaced 66 for 21, but when I trigger the thing I don't hear anything. I already checked if I wrote COMMON_ITEMTRE correctly and that's not the issue... code I use now: void onFunction0(jjPLAYER@ player) { if (!jjTriggers[21]) { jjTriggers[21] = true; jjSample(player.xPos, player.yPos, SOUND::COMMON_ITEMTRE); } } I'm curious what the issue is but I have no idea tbh. |
Thanks a lot!! I will try this code now. I wonder why you have to write player.xPos and player.yPos though. Seems irrelevant to me, what am I missing?
I just tried it but I don't hear the sound yet. To be extra clear about what I try: When Jazz (or another) walks through the event 'Trigger Zone 21 | onoff 1 | switch 0' the sound COMMON_ITEMTRE has to be played. But only the first time he walks through it, I don't want the sound to trigger every time, only when the thing is triggered the first time. But I think that would be the case automatically anyways? I just copy/pasted the first code you send in my AS file where the other AS code already worked. And replaced 66 for 21, but when I trigger the thing I don't hear anything. I already checked if I wrote COMMON_ITEMTRE correctly and that's not the issue... Code:
//Sugar rush counter |
Quote:
Quote:
The code Violet sent says: "when onFunction0 is called, if trigger 66 is currently off, turn trigger 66 on and play this sound." So it encompasses the functionality of a trigger zone within it, meaning you can safely replace the relevant trigger zone in your level with a text event (text ID parameter should be 0 to call onFunction0, AngelScript parameter should be 1 to inform the event you're trying to execute a script function and not display text to the player). Note that, the way Violet formulated the script, the sound will indeed play only once, unless you later deactivate the trigger (e.g. by dying) and come back to activate it again, but it's definitely deliberate wording on her part and not "the case automatically." Quote:
|
Thank you Seren, I will try this later. I understand most of what you explained, and Violet's code makes sense now. But what do you mean with 'AngelScript parameter should be 1'. What exactly should I put to '1'? Ooo, wait.. I think I remember I saw an AngelScript parameter in the text event window, you probably mean that.... Right? Anyways, thanks!!
|
Wow, it worked now!! After you explained it I actually remembered reading something about this in the readme but didn't think of using it here like this. Anyways this is my working code now:
Code:
//Sugar rush counter |
Excuse me, initially I wrote this message to ask a question but I already found an answer while explaining the question in detail xD So there's no question here anymore except maybe what I asked at the end of this message, although it's not that important because the code works now.
. I decided I want the door to open when Jazz stands close to the door, as if Jazz opened the door with the key. Instead of opening together with getting the key. So I have to add another piece of code. Somehow it worked already with what I made up, but only because I made it simpler because I don't know how to code 2 'if' functions. I want the door to open when walking through text event 101 but only if you walked through text event 100 first. I wrote this: Code:
Code:
//Sound effect for getting key |
Quote:
Quote:
Code:
jjTriggers[21] and not jjTriggers[24]Code:
jjTriggers[21] && !jjTriggers[24] |
Okay thank you, I see this now after I finished it. For next time this is better but now I use my less subtle but working way.
|
| All times are GMT -8. The time now is 02:48 AM. |
Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
JCF © 2001-Infinity Jazz2Online