TheIcyPickle
Member
Posts: 80
Threads: 16
Joined: Feb 2011
Reputation:
0
|
i need some help
ok so, I receive an error upon making your corrections in the hps file. I want a sound to be made when a player walks past a script box thing, called "popout1" but it only plays once the player has a key called "scarykey_1" Also, if possible , add at the same time, that naked penis figure flys in. (that part may be a pain, so if you can't explain it, its fine.)
here is my entire script.
////////////////////////////
// Run first time starting map
void OnStart()
{
GiveItemFromFile("lantern", "lantern.ent");
for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
AddUseItemCallback("", "scarykey_1", "door_1", "KeyOnDoor", true);
AddEntityCollideCallback("popout1", string& "Player", "PlaySoundAtEntity", true);
}
void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_1", false, true);
PlaySoundAtEntity("", "unlock_door", "door_1", 0, false);
RemoveItem("scarykey_1");
}
void PlaySoundAtEntity(string &in asplayer, string &in aspopout1, bool HasItem("scarykey_1")
{
PlaySoundAtEntity1("", "21_screams", "popout1", 0, false);
}
thanks for the help
|
|
05-28-2012, 04:24 AM |
|
Putmalk
Senior Member
Posts: 290
Threads: 13
Joined: Apr 2012
Reputation:
15
|
RE: i need some help
(05-28-2012, 04:24 AM)TheIcyPickle Wrote: ok so, I receive an error upon making your corrections in the hps file. I want a sound to be made when a player walks past a script box thing, called "popout1" but it only plays once the player has a key called "scarykey_1" Also, if possible , add at the same time, that naked penis figure flys in. (that part may be a pain, so if you can't explain it, its fine.)
here is my entire script.
////////////////////////////
// Run first time starting map
void OnStart()
{
GiveItemFromFile("lantern", "lantern.ent");
for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
AddUseItemCallback("", "scarykey_1", "door_1", "KeyOnDoor", true);
AddEntityCollideCallback("popout1", string& "Player", "PlaySoundAtEntity", true);
}
void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_1", false, true);
PlaySoundAtEntity("", "unlock_door", "door_1", 0, false);
RemoveItem("scarykey_1");
}
void PlaySoundAtEntity(string &in asplayer, string &in aspopout1, bool HasItem("scarykey_1")
{
PlaySoundAtEntity1("", "21_screams", "popout1", 0, false);
}
thanks for the help No flying naked man. Absolutely not. Get that crap out of your custom story, and never implement it. Or get laughed at. Your choice.
Anywho.
void PlaySoundAtEntity(string &in asplayer, string &in aspopout1, bool HasItem("scarykey_1"){
PlaySoundAtEntity1("", "21_screams", "popout1", 0, false);}
What is this? Can you please brush up on how functions work... In fact, just remove this stuff, it's worthless.
You want to play a sound when passing an entity? Use an AddEntityCollideCallback
So:
//place in OnStart
AddEntityCollideCallback("Player', "scriptareathingy", "PlaySound", false, 0);
void PlaySound(string &in asParent, string &in asChild, int alState)
{
if(HasItem("keyname") == false) return;
PlaySoundAtEntity("sound", "soundname.snt", "soundarea", 0, false);
}
That is the code basics. Replace wherever I wrote obvious placeholders with the names of your objects.
And never implement a flying naked body. Get out with that stuff. It's sickening.
|
|
05-28-2012, 04:34 AM |
|
TheIcyPickle
Member
Posts: 80
Threads: 16
Joined: Feb 2011
Reputation:
0
|
RE: i need some help
cool, good feedback guys! but would someone explain to me how the asparent and aschild things work?
And yeah, the popout scare is cheesy. Thanks for feedback!!!
|
|
05-28-2012, 06:12 AM |
|
Putmalk
Senior Member
Posts: 290
Threads: 13
Joined: Apr 2012
Reputation:
15
|
RE: i need some help
When you use AddEntityCollideCallback, you specify the function parameters as follows:
(string &in asParent, string &in asChild, string &in FunctionName, bool DeleteOnCollide, int alState)
This is why we call the function as:
AddEntityCollideCallback("Player", "Area", "Name", true, 0);
In this situation, "Player" is asParent, and "Area" is asChild.
Hence, when we make the function callback (this is the function that AddEntityCollideCallback creates), the parameters for this new function are
(string &in asParent, string &in asChild, int alState)
Where asParent is still "Player" and Area is still "asChild".
This is particularly useful if inside the function callback you want to add effects to area, instead of hardcoding the area name you can simply use asChild as the location for your event. Also, if you use asChild instead of the area name, you can call the same function with different areas and have effects play at those respective areas!
|
|
05-28-2012, 06:55 AM |
|
TheIcyPickle
Member
Posts: 80
Threads: 16
Joined: Feb 2011
Reputation:
0
|
RE: i need some help
Great! Everything is working except for 1 or 2 things.
1. Everytime I pass the script box, it makes a noise. I only want it to happen once.
2. Second, there a several different sounds that play each time I pass. I only want 21_scream10.ogg from 21_screams.snt to play.
Here is the new script.
AddEntityCollideCallback("Player", "popout1", "PlaySound", false, 0);
then
void PlaySound(string &in Player, string &in popout1, int alState)
{
if(HasItem("scarykey_1") == false) return;
PlaySoundAtEntity("21_scream10.ogg", "21_screams.snt", "popout1", 0, false);
}
|
|
05-28-2012, 07:27 AM |
|
Putmalk
Senior Member
Posts: 290
Threads: 13
Joined: Apr 2012
Reputation:
15
|
RE: i need some help
In AddEntityCollideCallback, change "false" to "true". The boolean argument specifies whether or not we delete the collision callback after one touch. (you don't always set this to true, but you have to be the judge on when you want it to happen every time or just once).
In the PlaySoundAtEntity function, the first parameter is merely the name of the sound that is being played. This allows it to be identified by the game, so you could stop it using the StopSound function. The second parameter is the actual sound. Replace 21_screams.snt with 21_scream10.ogg.
|
|
05-28-2012, 04:23 PM |
|
TheIcyPickle
Member
Posts: 80
Threads: 16
Joined: Feb 2011
Reputation:
0
|
RE: i need some help
ok, ok, so my new script should look like this:
AddEntityCollideCallback("Player", "popout1", "PlaySound", true, 0);
then
oid PlaySound(string &in Player, string &in popout1, int alState){ if(HasItem("scarykey_1") == false) return;
PlaySoundAtEntity("scream", "21_scream10.ogg", "popout1", 0, false);}
because "scream" is my sound box thing in the editor and the second thing is the actual sound file and "popout1" is my script box where the sound area is.
correction:
AddEntityCollideCallback("Player", "popout1", "PlaySound", true, 0);
then
void PlaySound(string &in Player, string &in popout1, int alState){ if(HasItem("scarykey_1") == false) return;
PlaySoundAtEntity("scream", "21_scream10.ogg", "popout1", 0, false);}
(This post was last modified: 05-28-2012, 05:15 PM by TheIcyPickle.)
|
|
05-28-2012, 05:13 PM |
|
Putmalk
Senior Member
Posts: 290
Threads: 13
Joined: Apr 2012
Reputation:
15
|
RE: i need some help
No. You need to learn how function parameters work.
When you add a function via AddEntityCollideCallback (in this case, we are creating a function called PlaySound), the callbacks will always be (string &in asParent, string &in asChild, int alState). Those parameters are what you'll see in the engine scripts wiki page: http://wiki.frictionalgames.com/hpl2/amn..._functions
Look at the entry for the collide callback:
void AddEntityCollideCallback(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int alStates);
Calls a function when two entites collide.
Callback syntax: void MyFunc(string &in asParent, string &in asChild, int alState)
asParentName - internal name of main object
asChildName - internal name of object that collides with main object (asterix (*) NOT supported!)
asFunction - function to call
abDeleteOnCollide - determines whether the callback after it was called
alStates - 1 = only enter, -1 = only leave, 0 = both
See that callback syntax? That is what the new function's parameters will always be!
So in the end it should be:
void OnStart()
{
//the collide callback is pretty much always in void OnStart(), don't have it floating by itself.
AddEntityCollideCallback("Player", "popout1", "PlaySound", true, 0);
}
void PlaySound(string &in asParent, string &in asChild, int alState)
{
if(HasItem("scarykey_1") == false) return;
PlaySoundAtEntity("scream", "21_scream10.ogg", "popout1", 0, false);
}
Never change those parameters. If you wanted to effect something in the function, you could.
Let's say I wanted a sound to play at the parent entity. Now this function is called by two different collide callbacks, with two different parent entities, but I always want it to play at the parent entity, then inside the callback function, I would write something like:
PlaySoundAtEntity("sound", "sound.snt", asParent, 0, false); //asParent == the parent entity. It may be a chair, it may be a player, it will change depending on what you want it to do.
Hope this is clear for you.
(This post was last modified: 05-28-2012, 05:30 PM by Putmalk.)
|
|
05-28-2012, 05:29 PM |
|
TheIcyPickle
Member
Posts: 80
Threads: 16
Joined: Feb 2011
Reputation:
0
|
RE: i need some help
sigh.. I feel like I have done what you said. Hmm, well. I have taken up enough of your time I'd say. But still...
http://www.mediafire.com/?5psmbvpe5peeh0k
is the link to the hps file. I know this wont be a learning experience for me, but could you look at it and see why I'm not doing it right and pretty please make the changes. I literally have exactly what you put and still, the sound does not play, but it did play w/ the .snt ext.
oh and to send it back, heres my email jpghalio@yahoo.com
this is probably the weirdest post you've seen
so thank you for still being here lol
(This post was last modified: 05-28-2012, 06:17 PM by TheIcyPickle.)
|
|
05-28-2012, 06:11 PM |
|
Putmalk
Senior Member
Posts: 290
Threads: 13
Joined: Apr 2012
Reputation:
15
|
RE: i need some help
Here, try this, see if it works. I am pretty sure .ogg files are acceptable in PlaySoundAtEntity. If not, you might want to try PlayGuiSound or something (non-3D sound effect).
I edited around some of the script which should make it easier to code. I commented them so you know what I did.
////////////////////////////
// Run first time starting map
void OnStart()
{
GiveItemFromFile("lantern", "lantern.ent");
for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
AddUseItemCallback("key1ondoor", "scarykey_1", "door_1", "KeyOnDoor", true);
AddEntityCollideCallback("Player", "popout1", "PlaySound", true, 0);
}
//instead of making 50 key on door scripts, just call this function with different items/doors and they should work
void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true); //I choose asEntity because that's the door
PlaySoundAtEntity("unlock", "unlock_door", asEntity, 0, false); //I choose asEntity because that's the door
RemoveItem(asItem); //I choose asItem as that's the item
}
//should always be asParent, asChild, alState
void PlaySound(string &in asParent, string &in asChild, int alState)
{
if(HasItem("scarykey_1") == false) return; //do nothing if no key
//I"m pretty sure you can place .ogg's here and have them play fine???
PlaySoundAtEntity("scream", "21_scream10.ogg", "popout1", 0, false);
}
(This post was last modified: 05-28-2012, 06:22 PM by Putmalk.)
|
|
05-28-2012, 06:21 PM |
|
|