Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Picking up an item gets a sound played
KingCrimson Offline
Junior Member

Posts: 45
Threads: 14
Joined: Jul 2012
Reputation: 0
#1
Picking up an item gets a sound played

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

Current Projects:
DADDY - 10%
(This post was last modified: 07-29-2012, 06:14 AM by KingCrimson.)
07-29-2012, 06:01 AM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#2
RE: Picking up an item gets a music played

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!

I rate it 3 memes.
07-29-2012, 06:11 AM
Find
KingCrimson Offline
Junior Member

Posts: 45
Threads: 14
Joined: Jul 2012
Reputation: 0
#3
RE: Picking up an item gets a music played

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:////////////////////////////
// Run when the map starts
void OnStart()
{
AddUseItemCallback("", "llave1", "puerta1", "unlock", true);

AddEntityCollideCallback("Player", "paso1", "ActivarArea", true, 1);

AddEntityCollideCallback("Player", "paso2", "Explotar", true, 1);

SetEntityCallbackFunc("linterna", "OnPickup");
}
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 asParent, string &in asChild, int alState)
{
SetEntityActive("agrippa", true);
PlaySoundAtEntity(string& asSoundName, string& girl_scream.snt, string& agrippa, float afFadeTime, bool false);
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}

Current Projects:
DADDY - 10%
(This post was last modified: 07-29-2012, 06:29 AM by KingCrimson.)
07-29-2012, 06:13 AM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#4
RE: Picking up an item gets a sound played

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/amn..._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()
{

}

I rate it 3 memes.
(This post was last modified: 07-29-2012, 07:19 AM by Adny.)
07-29-2012, 06:29 AM
Find




Users browsing this thread: 1 Guest(s)