[SCRIPT] Picking up an item gets a sound played - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SCRIPT] Picking up an item gets a sound played (/thread-17332.html) |
Picking up an item gets a sound played - KingCrimson - 07-29-2012 Hey, i'm trying to make a scene when the player has to pickup an item. But i want that, in the moment he picks it up, another entity becomes active (I've already done this) but also i need to get a sound played. How i'm supposed to do that? Thanks in advance RE: Picking up an item gets a music played - Adny - 07-29-2012 In the thread title it says "music" but in your description it says sound. You can play music by using the function: PlayMusic(string& asMusicFile, bool abLoop, float afVolume, float afFadeTime, int alPrio, bool abResume); asMusicFile = name of file and the extension ".ogg", (i.e. "song.ogg") abLoop = will the music continuously loop? True/False afVolume = a float of the volume of the music, max volume being 1.0f afFadeTimer = The amount of time it takes the music to fade out before stopping (or looping) alPrio = The priority, 0 being the highest (meaning it will always be heard) abResume = idk, just use false or, you can play sounds by using one of 2 functions: PlaySoundAtEntity(string& asSoundName, string& asSoundFile, string& asEntity, float afFadeTime, bool abSaveSound); asSoundName = Internal Name of the sound (can leave blank) asSoundFile = name of the sound file asEntity = the entity to play the sound at (can be "Player") afFadeTime = see music's function abSaveSound = false PlayGuiSound(string& asSoundFile, float afVolume); asSoundFile = see "PlaySoundAtEntity" afVolume = a float value for the volume of the sound PlayGuiSound will play a sound at the player. To use 1 of these 3 functions, simply copy/paste one into the same part of the script where you set the entity active, and fill out the information accordingly. Hope that helped! RE: Picking up an item gets a music played - KingCrimson - 07-29-2012 I think it works. But now i get these two errors: 1- "main (42,1): INFO : Compiling void Onpickup(string&in, string&in, int) 2- "main (45,27) : ERR : Expected "("" Here you've my .hps file's copy: Quote://////////////////////////// RE: Picking up an item gets a sound played - Adny - 07-29-2012 Well, PlaySoundAtEntity does just that: Plays a sound at an entity, making it ideal for "3D" sound effects (i.e. having sounds play behind or to the left/right of the player). It can also play a sound at the player himself, but in my opinion, that really over complicates it. PlayGuiSound is a much better "lightweight" alternative, and takes less time to write out. I use PlayGuiSound in scenarios where the sound makes sense to come from the player (i.e. voice acting), or the entity that makes the sound is in such close proximity that the player couldn't tell the difference anyways (i.e. unlocking a door). First, the syntax is incorrect, it doesn't match the callback you used (which I now changed to simplicity's sake). The callback syntax are the words inside the "()", which come after "void function". Use this page to make sure syntax match the callback used: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions Next, for the PlaySoundAtEntity function, you didn't really write any of it correctly. Basically, strings are names of things, and are declared (meaning inside of quotation marks i.e. "string" is declared). Bool stands for Boolean value, which is true/false, and float/int are number values; floats being decimals, and int being integers (non decimals). Aqui esta una revision: //////////////////////////// // Run when the map starts void OnStart() { AddUseItemCallback("", "llave1", "puerta1", "unlock", true); AddEntityCollideCallback("Player", "paso1", "ActivarArea", true, 1); AddEntityCollideCallback("Player", "paso2", "Explotar", true, 1); SetEntityPlayerInteractCallback("linterna", "OnPickup", true); } void ActivarArea(string &in asParent, string &in asChild, int alState) { SetEntityActive("paso2", true); } void unlock(string &in asItem, string &in asEntity) { SetSwingDoorLocked(asEntity, false, true); PlaySoundAtEntity("", "unlock_door", asEntity, 0, false); RemoveItem(asItem); } void Explotar(string &in asParent, string &in asChild, int alState) { SetPropHealth("explosive", 0.0f); PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false); PlaySoundAtEntity("", "react_scare", "Player", 0, false); PlaySoundAtEntity("", "close_door.snt", "Player", 0, false); GiveSanityDamage(5.0f, true); } void OnPickup(string &in asEntity) { SetEntityActive("agrippa", true); PlaySoundAtEntity("", "girl_scream", "agrippa", 0.5f, false); } //////////////////////////// // Run when entering map void OnEnter() { } //////////////////////////// // Run when leaving map void OnLeave() { } |