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


Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Key Script?
Author Message
Neurological Offline
Member

Posts: 71
Joined: Sep 2010
Reputation: 1
Post: #21
RE: Key Script?

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

Neurological - Music Entertainment
http://www.neuro-lab.net
09-16-2010 01:37 AM
Find all posts by this user Quote this message in a reply
Armored Cow Offline
Member

Posts: 72
Joined: Sep 2010
Reputation: 0
Post: #22
RE: Key Script?

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:

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
09-16-2010 02:23 AM
Find all posts by this user Quote this message in a reply
jens Offline
Frictional Games

Posts: 4,095
Joined: Apr 2006
Reputation: 202
Post: #23
RE: Key Script?

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.
09-16-2010 05:23 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Armored Cow Offline
Member

Posts: 72
Joined: Sep 2010
Reputation: 0
Post: #24
RE: Key Script?

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.
09-17-2010 05:18 AM
Find all posts by this user Quote this message in a reply
jens Offline
Frictional Games

Posts: 4,095
Joined: Apr 2006
Reputation: 202
Post: #25
RE: Key Script?

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.
09-17-2010 07:02 AM
Visit this user's website Find all posts by this user Quote this message in a reply
gosseyn Offline
Member

Posts: 63
Joined: Sep 2010
Reputation: 1
Post: #26
RE: Key Script?

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
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!
09-17-2010 12:46 PM
Find all posts by this user Quote this message in a reply
jens Offline
Frictional Games

Posts: 4,095
Joined: Apr 2006
Reputation: 202
Post: #27
RE: Key Script?

"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.
09-17-2010 01:00 PM
Visit this user's website Find all posts by this user Quote this message in a reply
gosseyn Offline
Member

Posts: 63
Joined: Sep 2010
Reputation: 1
Post: #28
RE: Key Script?

Thanks a lot, i am starting to understand the meanings of things.
09-17-2010 08:15 PM
Find all posts by this user Quote this message in a reply
Wafthrudnir Offline
Junior Member

Posts: 31
Joined: Sep 2010
Reputation: 0
Post: #29
RE: Key Script?

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*

"What is Amnesia?"
"This is Amnesia..."
"HOLY SHIT WTF?!!?"
09-17-2010 08:32 PM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)