Frictional Games Forum (read-only)
[SCRIPT] Assist me while I learn to script - 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] Assist me while I learn to script (/thread-37662.html)



Assist me while I learn to script - Toggle - 01-26-2016

This is pretty much just me asking how to do things at this point. So far, so good.


RE: Level Editor Crash - Mudbill - 01-27-2016

Could you post the LevelEditor.log instead from Documents\HPL2 ?


RE: Level Editor Crash - Toggle - 01-27-2016

Thread has been recycled.


RE: No Matching Signatures - Toggle - 01-29-2016

Also, is there a way to write a code so that if a player breaks a certain item in the environment, one of those glass display cases for example, a message pops up?


RE: No Matching Signatures - Mudbill - 01-29-2016

Use GetPropHealth() to check the state of an entity. If that "health" == 0, then it has been broken. IIRC there is also an OnBreak callback for the normal SetEntityCallbackFunc function. That one is probably even better to use.


RE: No Matching Signatures - Spelos - 01-29-2016

I'll just go ahead and put a more... newcomer-friendly version of what Mudbill posted earlier.

The events you're looking for are
void SetEntityCallbackFunc(string& asName, string& asCallback);
for the break callback
and
void SetMessage(string& asTextCategory, string& asTextEntry, float afTime);

PHP Code:
OnStart()
{
    
SetEntityCallbackFunc("nameOfTheEntity""functionToCall");
}

void functionToCall(string &in asEntityint alState//notice this function is called the same as referenced above.
{
    
SetMessage("categoryOfText""entryInCategory"0); //The last number is how long the message should be displayed, 0 = calculated depending on the length of the text. The text and category are in a different file called "extra_english.lang" in the custom story folder.


Your extra_english.lang should contain something like this:
PHP Code:
<LANGUAGE>
        <
CATEGORY Name="CustomStoryMain">
            <
Entry Name="Description"Description of your story</Entry>
        </
CATEGORY>

        <
CATEGORY Name="categoryOfText"//Notice the name of the category & entry are referenced in your .hps file.
            
<Entry Name="entryInCategory">Text to appear on screen.</Entry>
        </
CATEGORY>
</
LANGUAGE



RE: No Matching Signatures - Toggle - 01-29-2016

You are just so helpful, you kind and wonderful person, you. I am becoming a big fan. Heart


RE: Assist me while I learn to script - Toggle - 01-29-2016

Okay, next question is.. Do I need to use timers to play a sound at regular intervals UNTIL the player goes over to interact with the script area? Or is there a different way to accomplish that? Not a loop, though. What I want is for the sound to play every 30 seconds or so, until the player gets in the proper place, at which time the sound should stop.


RE: Assist me while I learn to script - Radical Batz - 01-29-2016

(01-29-2016, 08:29 PM)Toggle Wrote: Okay, next question is.. Do I need to use timers to play a sound at regular intervals UNTIL the player goes over to interact with the script area? Or is there a different way to accomplish that? Not a loop, though. What I want is for the sound to play every 30 seconds or so, until the player gets in the proper place, at which time the sound should stop.

You can use an if statement but if you want to make it easier. You can like just when the player collides with an area to where you want him to go then you can use a StopSound{"name of the sound", 1); to stop the sound that's playing.

For that you need an addentitycollidecallback in void OnStart


RE: Assist me while I learn to script - Spelos - 01-29-2016

Final product:
A sound (GUI, that means it's not in 3D) plays Every 30 seconds or so... until the Player collides with an area.

What you will need:
  • Level Editor
    • Area in the map (remember the name! For this tutorial, it's "stopSoundArea")
    • A sound to play (for this tutorial, it's in .ogg format, keep it at that. "rickroll.ogg". Keep it in the "sounds" folder of your custom story)
  • Script events
    • void AddTimer(string& asName, float afTime, string& asFunction); //Adding and working with timers
    • void PlayGuiSound(string& asSoundFile, float afVolume); //Play a sound, not using
      3D

    • void AddEntityCollideCallback(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int alStates); //Calls a function when two entities collide
    • int RandInt(int alMin, int alMax); //Selects a random integer between Min and Max value.

The actual script:
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""stopSoundArea""stopSoundFunction"true1); //Calls the "stopSoundFunction" when Player hits "stopSoundArea".

    
AddTimer("loop"RandInt(2535), "PlayLoopSound"); //Adds the timer to play the Loop sound.
}

void PlayLoopSound(string &in asTimer//The timer function.
{
    
PlayGuiSound("rickroll.ogg"1.0f); //Plays the file one time and ends.
    
AddTimer("loop"RandInt(2535), "PlayLoopSound"); //Waits 25 to 35 seconds and repeats the function.
}

void stopSoundFunction(string &in asParentstring &in asChildint alState)
{
    
RemoveTimer("loop"); //Removes the timer and breaks the loop.