Frictional Games Forum (read-only)
Scripting, need urgent help! - 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: Scripting, need urgent help! (/thread-9259.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13


RE: Scripting, need urgent help! - MrCookieh - 07-27-2011

Kyle Wrote:There is no SetEntityCallbackFunc.
There is:
Spoiler below!
Code:
void SetEntityCallbackFunc(string& asName, string& asCallback);

Calls a function when the player interacts with a certain entity.
Callback syntax: void MyFunc(string &in asEntity, string &in type)
Type depends on entity type and includes: “OnPickup”, “Break”, “OnIgnite”, etc


Code:
void OnEnter ()
{
AddUseItemCallback("", "keyone", "door1", "UsedKeyOnDoor", true);
SetEntityCallbackFunc("notethree", "Func");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door1", 0, false);
RemoveItem("keyone");
}
void Func(string &in asEntity, string &in type)
{
if(type == "OnPickup")
{
PlaySoundAtEntity("", "15_body_impact.snt", "Player", 0, false);
PlaySoundAtEntity("", "react_pant5.snt", "Player", 0, false);
StartPlayerLookAt("Player", 3.0f, 3.0f, "");
AddTimer("atticscare", 1, "Func2");
}
}
void OnLeave ()
{
}

This is your fixed code.

A function works like this:
First you need a callback, which 'calls' the function: (for example)
SetEntityCallbackFunc("notethree", "Func");
-> This will call the function "Func".

A function is a part of the code, which only runs through, if it's called.
It starts with void FuncNameHere(ParametersHere){}
In the brackets are the actions, which should be triggered, when the
callback happens


RE: Scripting, need urgent help! - JetlinerX - 07-27-2011

OMG!!! I GET IT NOW!!! I totally see what everyone was talking about! That code also works to play the sound! YESSSSSSS!!!

One last thing, this is probably in the extra_eng most likely, but how do I make some sort of subtitle on the bottom after the sound, for instance:

"That sound came from the attic right above me, whats going on?"

Also, my second key is not working with this code and I have tried everything I can...

Code:
void OnEnter ()
{
AddUseItemCallback("", "keyone", "door1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "key_attic", "atticdoor", "UsedKeyOnDoor", true);
SetEntityCallbackFunc("key_attic", "Func");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door1", 0, false);
RemoveItem("keyone");
}
void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("atticdoor", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "atticdoor", 0, false);
RemoveItem("key_attic");
}
void Func(string &in asEntity, string &in type)
{
if(type == "OnPickup")
{
PlaySoundAtEntity("", "15_body_impact.snt", "Player", 0, false);
PlaySoundAtEntity("", "react_pant5.snt", "Player", 0, false);
StartPlayerLookAt("Player", 3.0f, 3.0f, "");
AddTimer("atticscare", 1, "OnPickup");
}
}
void OnLeave ()
{
}



RE: Scripting, need urgent help! - xiphirx - 07-27-2011

Check your syntax, you're missing a closing bracket for "UsedKeyOnDoor".

Also, refer to http://wiki.frictionalgames.com/hpl2/amnesia/script_functions

void SetMessage(string& asTextCategory, string& asTextEntry, float afTime);
Displays a message on the screen.

asTextCategory - the category in the .lang file
asTextEntry - the entry in the .lang file
afTime - determines how long the message is displayed. If time is < =0 then the life time is calculated based on string length.


RE: Scripting, need urgent help! - JetlinerX - 07-27-2011

On the first "UsedKeyOnDoor" or the second? I cant see what one you mean as they both look the same.

Also, where does that SetMessage go so that it knows when to come up?

Also, I totally forgot about the Scripts Func page! Thanks for reminding me!


RE: Scripting, need urgent help! - xiphirx - 07-27-2011

Ah, I didn't notice the scrollbar for your script Tongue

Code:
void OnEnter ()
{
    AddUseItemCallback("", "keyone", "door1", "UsedKeyOnDoor", true);
    AddUseItemCallback("", "key_attic", "atticdoor", "UsedKeyOnDoor", true);
    SetEntityCallbackFunc("key_attic", "Func");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door1", 0, false);
    RemoveItem("keyone");
}
void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("atticdoor", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "atticdoor", 0, false);
    RemoveItem("key_attic");
}
void Func(string &in asEntity, string &in type)
{
    if(type == "OnPickup")
    {
        PlaySoundAtEntity("", "15_body_impact.snt", "Player", 0, false);
        PlaySoundAtEntity("", "react_pant5.snt", "Player", 0, false);
        StartPlayerLookAt("Player", 3.0f, 3.0f, "");
        AddTimer("atticscare", 1, "OnPickup");
    }
}
void OnLeave ()
{
}

Now pay attention to this part
Code:
    AddUseItemCallback("", "keyone", "door1", "UsedKeyOnDoor", true);
    AddUseItemCallback("", "key_attic", "atticdoor", "UsedKeyOnDoor", true);

You're calling the same key function for both doors here, you just forgot the "2" for the second door

Code:
    AddUseItemCallback("", "keyone", "door1", "UsedKeyOnDoor", true);
    AddUseItemCallback("", "key_attic", "atticdoor", "UsedKeyOnDoor2", true);




RE: Scripting, need urgent help! - JetlinerX - 07-27-2011

OH CRAP! Nice call! Dang it, this stuff is so tedious!
Hm, It would appear the door remains locked after using the key... ideas?


RE: Scripting, need urgent help! - JenniferOrange - 07-27-2011

To set a message after the sound:

{
PlaySoundAtEntity("", "15_body_impact.snt", "Player", 0, false);
PlaySoundAtEntity("", "react_pant5.snt", "Player", 0, false);
StartPlayerLookAt("Player", 3.0f, 3.0f, "");
AddTimer("atticscare", 1, "OnPickup");
SetMessage("Messages", "scare", 0);
}

thats for your .hps .

This is for your .lang file=
Add this Category, if you don't already have it:
Code:
<CATEGORY Name="Messages">
      <Entry Name="scare">yourtexthere</Entry>
</CATEGORY>

And there you go! Smile




RE: Scripting, need urgent help! - JetlinerX - 07-27-2011

So the script is just reading it in order, so when the sounds play, it will read the message next? Interesting as 99% of the other parts of the code dont do that, which is why its so confusing! XD

Thanks again "Jennifer" you always come through Wink

Ill let you all know what the results are.


RE: Scripting, need urgent help! - JetlinerX - 07-27-2011

The message did not pop up after picking up the key :/


RE: Scripting, need urgent help! - JetlinerX - 07-28-2011

Got it working ^^^^