Frictional Games Forum (read-only)
Key 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Key Script? (/thread-4364.html)

Pages: 1 2 3


RE: Key Script? - Neurological - 09-16-2010

Creating a new entry would be better. The name it have to be wrote on CustomSubItemTypeName.


RE: Key Script? - Armored Cow - 09-16-2010

I'm having trouble making a key script as well.

The door I am trying to open is named "door_1".

The key is named "key_study" (I think. It's a key that is produced when you shatter a wine bottle, so there's no way to name it, but the option in the menu to have a key inside is named "key_study").

The thing is, when I pick up the key it says I've found the Machine Room Key, and when I try to use it on the door it says "Cannot be used this way!"

This is my code:

Code:
void OnStart()
{
    AddUseItemCallback("useexit", "key_study", "door_1", "UseKey", true);
}

void UseKey(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked(asEntity, false, true);

    RemoveItem(asItem);
}

Any help?

EDIT: Also, I really don't know any code and simply copied this from earlier in the thread. It would be great if someone could explain what these commands do.

EDIT2: I tried doing this similarly with a key that was just sitting on a table and got it to work since I was able to name it, but I would still like an answer to my previous question if possible. Also, how do I code in a 2nd key? The thing is, there's a key in the desk door that opens the door to the room but I'm not sure how to code this in.
Thanks!

EDIT3: Got it all figured out


RE: Key Script? - jens - 09-16-2010

Don't edit the original .lang files, that will only mess it up and you will not be able to share your work with other (why would other users want to overwrite their lang files with your specific stuff in it?).

Make a new lang file and add it to your custom story folder, as instructed on the wiki.


RE: Key Script? - Armored Cow - 09-17-2010

If anyone could answer as to how to name the key inside of the bottle, I would be much appreciative.

Anyway, I have a new question.

How do I make it so that if the player tries to open a locked door (named 'door_2' fyi), it says "The door is locked."?

I also would like the message to obviously not appear when the door has been unlocked.


RE: Key Script? - jens - 09-17-2010

The key inside a bottle is "tricky" when it comes to the name, it will get the name of the entity name of the bottle + the name of the entity or body name of the key or soemthing like that. I think if the jar is named key_jar_1 the name of the key is "key_jar_1_item". At least that is the name of the key in the jar from the game.


RE: Key Script? - gosseyn - 09-17-2010

i have some questions regarding the key and door script :
- where is the "useexit" string coming from, what is its purpose?

and tell me here if i am wrong or right here, i commented the AddUseItemCallback function from the wiki
Code:
AddUseItemCallback(
     string& asName, //i don't understand the purpose of this parameter
     string& asItem, //the item we want to use (the key)
     string& asEntity, //the entity we want to use the item on (the door)
     string& asFunction, //the result of the action of using the key on the door, launching SetSwingDoorLocked function
     bool abAutoDestroy //destroy the key after use or not
     );

Why is this inside OnStart ? Is it something that stays in memory waiting to be triggered ? The word Callback is confusing me.

Thanks!


RE: Key Script? - jens - 09-17-2010

"useexit" is only the name of the Callback, so you can do RemoveUseItemCallback("useexit"); and it would not be possible to use the key any longer.

A Callback could also be thought of as a trigger, something that occurs at a specified event, in this case when using a specific key on a specific door.

It is in OnStart because it is something that should be active in the level from the very start and then stay in the back, checking for when its event occurs. So you are correct in your assumption, it is something that "stays in memory waiting to be triggered".

asName = as I explained before.
then the rest are correct except, abAutoDestroy. This is the actual Callback, so false means that you can keep using the key on the door, true is that you can only do it one time, then it will say that you can not use the key on the door. It does not remove the key from the inventory.

Removing of the key is done in the callback, with the line "RemoveItem(asItem);" where asItem references the item used on the door, in this case the key.


RE: Key Script? - gosseyn - 09-17-2010

Thanks a lot, i am starting to understand the meanings of things.


RE: Key Script? - Wafthrudnir - 09-17-2010

Off topic:
Holy sh*t...I just knew LUA until now and was messing around with it...but i hated the Syntax of it...AngelScript seems to be much better.

Is it hard to implement this in your own programms? Or is it as easy as with Lua?

Are we able to use classes or is it a special part of AngelScript, that needs to be implemented too? Just wonder, dunno if it would be useful anyway.

Anyway, wish you all a nice weekend!

Skål *sipping Jägermeister*