Frictional Games Forum (read-only)
[SCRIPT] Script 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: [SCRIPT] Script help (/thread-18320.html)



Script help - Vasco - 09-14-2012

I'm working on my own Custom story at the moment (actually, this is my first Amnesia CS). I'm not good in scripting, so I already have some questions. For example:
- Is there a way to script an area to call a function when a certain type of entity interacts with it? For example, I put inside an area any random book (not a concrete book with a name "book_that_calls_callback", but a random one) or random barrel, random piece of human arm etc. and this calls a function?
- Is there a way to make a rope area inactive? Or how can I script a situation, when I use a "rope" item near a hole - and a rope appears, that can be used as ladder?
- Is there a way to make a player drop a thing that he is holding in his hands at the moment? For example, the player walks through the corridor having a barrel/chair/book/Stephano/etc in his hand and whenever he goes inside an area - he drops this entity, and he has to grab it once again.


RE: Script help - Robby - 09-14-2012

Question 1: Yes. Don't understand the random book part.

Question 2: Don't know about rope areas. I worked with ladder areas, but not rope areas.

Question 3: Unsure about that. Try using "ChangePlayerStateToNormal();" (without quotes).


RE: Script help - Vasco - 09-14-2012

(09-14-2012, 01:01 PM)Nemet Robert Wrote: Question 1: Yes. Don't understand the random book part.


I mean, that there is a library full of books in the map, and any of them can call a function if put inside the scriptarea.


RE: Script help - Robby - 09-14-2012

Well, that may be a bit difficult. You'll have to use the "AddEntityCollideCallback" script on each book.

Like this:

AddEntityCollideCallback("book_1", "ScriptAreaName", "book_1_function", true, 1);

AddEntityCollideCallback("book_2", "ScriptAreaName", "book_2_function", true, 1);


etc.

If you want like "if one book triggers that, the others can no longer" kind of thing, that will need a "Local" or "Global" int. Something that I am working with right now.


RE: Script help - FlawlessHappiness - 09-14-2012

You just have to use a for script. I can paste it when i get home...


RE: Script help - Robby - 09-14-2012

Just noticed I typed incorrectly in the previous post. Should be fine now!


RE: Script help - Wapez - 09-14-2012

Question 1:
The solution to this is using a "for loop". That's a script that involves alot of entities, in one line of code. Like this:

Let's say you have added 50 books. You add a "for loop" that involves the numbers 1-50. The integer (shortened "i") is every number between 1 and 50.

PHP Code:
for(int i=1;i<50;i++) 

Now we need to add a function.

PHP Code:
AddEntityCollideCallback("Book_"+i"ScriptArea""YourFunction"true1); 


Take a look at the AddEntityCollideCallback. Instead of using the name ("Book_1") we added ("Book"+i). And since the "for loop" made the "i" mean any number between 1 and 50, every book that is named ("Book_" and a number between 1 and 50 after the underscore) will call the function "YourFunction" when they collide with the "ScriptArea".

At the end, after adding opening and closing brackets, it should look like this:

for(int i=1;i<50;i++){
AddEntityCollideCallback("Book_"+i, "ScriptArea", "YourFunction", true, 1);
}

Question 2:
The solution to this is the un-check the "Active" check-box in your ladder area, in the editor. That makes it unable to use. After that, you simple need to activate it with this script:

PHP Code:
SetEntityActive("LadderArea"true); 


Put that in the script function when they use the rope on the hole.

Question 3:
You can use this script:

PHP Code:
ChangePlayerStateToNormal(); 

It will make the player drop the item he is holding. Just copy the line and add it to your function.


RE: Script help - Vasco - 09-14-2012

Wow, that's great! Thanks =D Thanks to everyone. I've been working on my CS for nearly a month, and these scripts were the most difficult.