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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help How to achieve this scenario?
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#1
How to achieve this scenario?

The scenario;

You enter a room, the sound of a plate or vase smashing is heard from another room, the centre dot 'looks' to where the sound came from, then the sound of a monster walking is heard followed by the sound of a door shutting.

How would I go about doing this? I have the actual level built ready, I just have no clue about scripting, I understand the basic idea of it but I cant just open up a text doc and type in what I want to do, whereas I have no problem opening the level editor and building a random set of aesthetically pleasing rooms (imo Smile).

01-30-2013, 01:54 AM
Find
NaxEla Offline
Senior Member

Posts: 415
Threads: 5
Joined: Dec 2012
Reputation: 28
#2
RE: How to achieve this scenario?

Well, you'll need to use timers and these functions:
PHP Code: (Select All)
void AddTimer(stringasNamefloat afTimestringasFunction);
void PlaySoundAtEntity(stringasSoundNamestringasSoundFilestringasEntityfloat afFadeTimebool abSaveSound);
void StartPlayerLookAt(stringasEntityNamefloat afSpeedMulfloat afMaxSpeedstringasAtTargetCallback);
void StopPlayerLookAt(); 

In Ruins [WIP]
01-30-2013, 02:28 AM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#3
RE: How to achieve this scenario?

Thanks a lot for the commands, very helpful, though im still a long way off understanding what to do with it Smile

As an example for now, where it says 'asName', do you put after that the filename + extension or does it actually have to be the full path to the file?

01-30-2013, 04:07 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#4
RE: How to achieve this scenario?

asName is the name of the timer. If you don't know how to use it leave it like this: ""

If you'd like to know I'll just selfpromote my own thread here Wink
http://www.frictionalgames.com/forum/thread-18368.html

You should be able to find your answer there Smile

You might want to check up some basic scripting, and how fx. timers work.

Trying is the first step to success.
01-30-2013, 08:05 AM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#5
RE: How to achieve this scenario?

(01-30-2013, 01:54 AM)serbusfish Wrote: The scenario;

You enter a room, the sound of a plate or vase smashing is heard from another room, the centre dot 'looks' to where the sound came from, then the sound of a monster walking is heard followed by the sound of a door shutting.

How would I go about doing this? I have the actual level built ready, I just have no clue about scripting, I understand the basic idea of it but I cant just open up a text doc and type in what I want to do, whereas I have no problem opening the level editor and building a random set of aesthetically pleasing rooms (imo Smile).

Okay, it would be like this:

void OnStart()
{
AddEntityCollideCallback("Player", "Area", "Stuff", true, 1); //The area is when you enter the room.
}

void Stuff (string &in asParent, string &in asChild, int alState)
{
SetPropHealth("Vase_to_be_broken", 0);
StartPlayerLookAt("Area_to_look_at", 1, 1, ""); ///The numbers can change if necessary
AddTimer("", 1, "Sound");
}

void Sound (string &in asEntity)
{
///Play monster walking sound
AddTimer("", 1, "Anothersound");
}

void Anothersound (string &in asTimer)
{
///Door shutting sound
StopPlayerLookAt();
}

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
(This post was last modified: 01-30-2013, 12:14 PM by The chaser.)
01-30-2013, 09:35 AM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#6
RE: How to achieve this scenario?

OK, I'll expand a bit on what others have said.

First, for some basic understanding of how the game and the script interact with each other, read this short article.

Now, here we go:
(01-30-2013, 01:54 AM)serbusfish Wrote: You enter a room,
To detect if a player has entered a room or not, you normally set up the script to detect a collision with a script area. So, first make sure that the map itself contains a script area that can be used for this. Depending on what exactly you want to happen, you can just put a thin script area right in front of the door, or you can place a big box in the center of the room to define an inner region where this should happen. In the script file, you would use an AddEntityCollideCallback() to "subscribe to" collision detection with that area, as described above by The chaser and BeeKayK (a more detailed explanation on how to use basic functions and parameters here, and of callbacks here)

(01-30-2013, 01:54 AM)serbusfish Wrote: the sound of a plate or vase smashing is heard from another room,
Similarly, you need something in your level to define the source of the sound. Either edit the script file to break an actual vase entity using SetPropHealth() as The chaser did, or use the level editor to add a script area in the other room (or just near or behind the wall, in empty space - if there's no really another room) to define where the sound should come from. Once this is done, just find the appropriate sound, and edit the script file to make a call to PlaySoundAtEntity() in place of SetPropHealth(), like this (replace the names to match the names in your level - "internal.sound.id" can be whatever you like, the number 0.0f is sound fade in time in seconds (the f is just some data type suffix, don't worry about that)):
PHP Code: (Select All)
PlaySoundAtEntity("internal.sound.id""SoundFileName.snt""ScriptAreaName"0.0f false); 

(01-30-2013, 01:54 AM)serbusfish Wrote: the centre dot 'looks' to where the sound came from,
Use StartPlayerLookAt() as described by The chaser above, and then AddTimer() so that you can exit the forced look-at state after some time, by calling StopPlayerLookAt() inside the timer callback (which The chaser forgot to do).

(01-30-2013, 01:54 AM)serbusfish Wrote: then the sound of a monster walking is heard
Either immediately use PlaySoundAtEntity() as before (but perhaps on a different script area) to play a monster walking sound (just find some footstep sounds that came with the game), or first add a timer if you want to offset the sound playback by some time amount.

(01-30-2013, 01:54 AM)serbusfish Wrote: followed by the sound of a door shutting.
Same as before.

P.S. Consult the engine script functions reference page to find out more about the available functions, and how to use them (what their parameters mean).
(This post was last modified: 01-30-2013, 11:55 AM by TheGreatCthulhu.)
01-30-2013, 11:48 AM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#7
RE: How to achieve this scenario?

Wow thanks a lot guys, I really appreciate that info, im starting to get my head around scripting and managed to put ambient music into my level, its small but its a start.

Im going to go through your info step by step, have a mess around and hopefully i'll achieve the effect im after Smile

01-31-2013, 01:58 AM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#8
RE: How to achieve this scenario?

Ok im a little stuck. I cant get the vase to break when I enter the room. Here is what I have atm:

Quote: {
AddEntityCollideCallback("Player", "ScriptArea_2", "stuff", true, 1); //The area is when you enter the room.
{
SetPropHealth("pot_plant_small02_1", 0);
}
}
Now I know more is needed to make the vase break when I enter the area but I cant figure out what, I tried adding the other lines but I get an error and my map wont load :?

01-31-2013, 05:30 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#9
RE: How to achieve this scenario?

You haven't done the script correctly.
You need to understand how the script works.

This is how it should look:

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea_2", "BreakPotPlant", true, 1);
}

void BreakPotPlant(string &in asParent, string &in asChild, int alState)
{
SetPropHealth("pot_plant_small02_1", 0);
}

IMPORTANT
You cannot have 2 void OnStart's, so you'll have to take the line in this void OnStart, and put it inside your void OnStart next to all the other lines.

Trying is the first step to success.
(This post was last modified: 01-31-2013, 06:05 PM by FlawlessHappiness.)
01-31-2013, 06:03 PM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#10
RE: How to achieve this scenario?

Thanks for being patient with me, but something is still wrong because I pasted that exact code and the game throws up an error message saying 'ERR - expected '('.

It must have something to do with the line

"void BreakPotPlant(string &in asParent, string &in asChild, int alState)"

because the map loads when this is deleted. Am I supposed to replace the text in this line?

If it helps here is the entire content of my .hps file so far:

//===========================================
     // This runs when the map first starts
     void OnStart()
{

        if(ScriptDebugOn())

        
    {
              
       GiveItemFromFile("tinderbox", "tinderbox.ent");
          {
              AddEntityCollideCallback("Player", "ScriptArea_2", "BreakPotPlant", true, 1);
                 }

                     void BreakPotPlant(string &in asParent, string &in asChild, int alState)
                         {
                             SetPropHealth("pot_plant_small02_1", 0);
                         }
     }         
  
}        
      
     //===========================================
     // This runs when the player enters the map
     void OnEnter()
   {
  
   //----AUDIO----//
    PlayMusic("10_amb", true, 5, 1, 0, true);
}
     //===========================================
     // This runs when the player leaves the map
     void OnLeave()
     {
     }

(This post was last modified: 02-01-2013, 04:10 AM by serbusfish.)
02-01-2013, 04:09 AM
Find




Users browsing this thread: 1 Guest(s)