Frictional Games Forum (read-only)
Add all simple scripts here! - 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: Add all simple scripts here! (/thread-5702.html)

Pages: 1 2 3


Add all simple scripts here! - HumiliatioN - 12-12-2010

Okay im making my first map and level editor is easy to use, but i have problems with scripting i just wanna add here some simple scripts example.

- Using item like crowbar with door and combine items?

- Two levels combine doors (I mean hub)

- Enemy trigger some areas and hallucinating enemy, scary door, player insanity some areas

- Lever making with combines door?

- Playing sound some areas.

Okay thats it if i get answered these scripts i thank you so much!

Please Wink


RE: Add all simple scripts here! - Akumasama - 12-12-2010

Pretty much everything you asked, is either on the Wiki or on the forum.
search through those first, and ask if you still can't figure it out Smile


RE: Add all simple scripts here! - HumiliatioN - 12-13-2010

(12-12-2010, 11:34 PM)Akumasama Wrote: Pretty much everything you asked, is either on the Wiki or on the forum.
search through those first, and ask if you still can't figure it out Smile

I searched it but doesnt get it Sad And not working all of these scripts example. Scary door and enemy trigger i need better explanations on these scripts. Plz Angel


RE: Add all simple scripts here! - Akumasama - 12-13-2010

Well, to start out, try writing it yourself.
We will be glad to help you fix it.

If you just started with scripting, take a look at other scripts to see the structure.
For example, this is how I started: http://frictionalgames.com/forum/thread-5425.html


RE: Add all simple scripts here! - HumiliatioN - 12-13-2010

(12-13-2010, 03:43 PM)Akumasama Wrote: Well, to start out, try writing it yourself.
We will be glad to help you fix it.

If you just started with scripting, take a look at other scripts to see the structure.
For example, this is how I started: http://frictionalgames.com/forum/thread-5425.html

Okay heres one question: Where i put all scripts because there are 3 areas?

OnStart() What scripts belongs here?

OnEnter() here?

OnLeave() here?

Im confused because i tried OnStart my 3 scripts put but there are couple errors. end of file.. example:

And how i seperate all void codes..

Okay this one is working script: Two doors with open keys.. I get it but.. where i put now Enemy trigger script area?

void OnStart()
{
AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
RemoveItem("key_1");
AddDebugMessage("KeyOnDoor", false);
}

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_2", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}




////////////////////////////
// Run when entering map
void OnEnter()
{
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}


RE: Add all simple scripts here! - Akumasama - 12-13-2010

(12-13-2010, 04:02 PM)HumiliatioN Wrote: OnStart() What scripts belongs here?

OnEnter() here?

OnLeave() here?
OnStart(): The first time you enter an map
OnEnter(): Every time you enter an map
OnLeave(): Whenever you leave the map


(12-13-2010, 04:02 PM)HumiliatioN Wrote: Im confused because i tried OnStart my 3 scripts put but there are couple errors. end of file.. example:
You'll have to give us the errors and/or the script for this one...


(12-13-2010, 04:02 PM)HumiliatioN Wrote: And how i seperate all void codes..
Void basically means that you start a new function.
Like this:
Code:
void funcname(syntax){
     stuff you want to happen
}
void funcname2(syntax){
     stuff you want to happen
}


(12-13-2010, 04:02 PM)HumiliatioN Wrote: Okay this one is working script: Two doors with open keys.. I get it but.. where i put now Enemy trigger script area?

void OnStart()
{
AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
RemoveItem("key_1");
AddDebugMessage("KeyOnDoor", false);
}

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_2", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}




////////////////////////////
// Run when entering map
void OnEnter()
{
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}
Well, the thing I do, is put every function that is NOT in any of the "on---" functions, at the bottom of the script.
This way, you won't have to search in between all of your trigger-functions.
Code:
void OnStart()
{
}

////////////////////////////
// Run when entering map

void OnEnter()
{
    AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
    AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true)
}

////////////////////////////
// Run when leaving map

void OnLeave()
{
}

////////////////////////////
// Actual functions

void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
    RemoveItem("key_1");
    AddDebugMessage("KeyOnDoor", false);
}    

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_2", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}

I put your key code in OnEnter, because you'd want to be able to open it every time you enter the level, and not just the first time.
Triggers that scare you the first time you enter a map for example, should be placed in OnStart, so it will not trigger again when entering the map for the second time.


RE: Add all simple scripts here! - HumiliatioN - 12-13-2010

(12-13-2010, 04:16 PM)Akumasama Wrote:
(12-13-2010, 04:02 PM)HumiliatioN Wrote: OnStart() What scripts belongs here?

OnEnter() here?

OnLeave() here?
OnStart(): The first time you enter an map
OnEnter(): Every time you enter an map
OnLeave(): Whenever you leave the map


(12-13-2010, 04:02 PM)HumiliatioN Wrote: Im confused because i tried OnStart my 3 scripts put but there are couple errors. end of file.. example:
You'll have to give us the errors and/or the script for this one...


(12-13-2010, 04:02 PM)HumiliatioN Wrote: And how i seperate all void codes..
Void basically means that you start a new function.
Like this:
Code:
void funcname(syntax){
     stuff you want to happen
}
void funcname2(syntax){
     stuff you want to happen
}


(12-13-2010, 04:02 PM)HumiliatioN Wrote: Okay this one is working script: Two doors with open keys.. I get it but.. where i put now Enemy trigger script area?

void OnStart()
{
AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
RemoveItem("key_1");
AddDebugMessage("KeyOnDoor", false);
}

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door_2", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}




////////////////////////////
// Run when entering map
void OnEnter()
{
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}
Well, the thing I do, is put every function that is NOT in any of the "on---" functions, at the bottom of the script.
This way, you won't have to search in between all of your trigger-functions.
Code:
void OnStart()
{
}

////////////////////////////
// Run when entering map

void OnEnter()
{
    AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
    AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true)
}

////////////////////////////
// Run when leaving map

void OnLeave()
{
}

////////////////////////////
// Actual functions

void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
    RemoveItem("key_1");
    AddDebugMessage("KeyOnDoor", false);
}    

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_2", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}

I put your key code in OnEnter, because you'd want to be able to open it every time you enter the level, and not just the first time.
Triggers that scare you the first time you enter a map for example, should be placed in OnStart, so it will not trigger again when entering the map for the second time.

Okay good now i understand something but i copied that last code what you write and not working Sad Why?


RE: Add all simple scripts here! - Akumasama - 12-13-2010

Code:
void OnStart()
{
}

////////////////////////////
// Run when entering map

void OnEnter()
{
    AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
    AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true);
}

////////////////////////////
// Run when leaving map

void OnLeave()
{
}

////////////////////////////
// Actual functions

void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
    RemoveItem("key_1");
    AddDebugMessage("KeyOnDoor", false);
}    

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_2", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}

My bad, forgot the ";" after AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true).
This is also part of what you must learn to do.
Seek out the errors in your script.
Most of the the time, the error message you get, tells you where your error is, and what it's missing/wrong.

In your case, it should say something like: "Expected ";""


RE: Add all simple scripts here! - HumiliatioN - 12-13-2010

(12-13-2010, 04:54 PM)Akumasama Wrote:
Code:
void OnStart()
{
}

////////////////////////////
// Run when entering map

void OnEnter()
{
    AddUseItemCallback("", "key_1", "door_1", "KeyOnDoor", true);
    AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true);
}

////////////////////////////
// Run when leaving map

void OnLeave()
{
}

////////////////////////////
// Actual functions

void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, false);
    RemoveItem("key_1");
    AddDebugMessage("KeyOnDoor", false);
}    

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("door_2", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "door_1", 0.0f, true);
}

My bad, forgot the ";" after AddUseItemCallback("", "key_2", "door_2", "KeyOnDoor2", true).
This is also part of what you must learn to do.
Seek out the errors in your script.
Most of the the time, the error message you get, tells you where your error is, and what it's missing/wrong.

In your case, it should say something like: "Expected ";""

Oh i see.. Now it works.. hmm this takes time i know these errors but lines are confusing me sometimes. When main errors appears...

Thank you for this tutorial very helpful! I ask more error scripts if something is wrong Smile


RE: Add all simple scripts here! - Akumasama - 12-13-2010

No problem.
This is how you learn scripting, not asking for stuff out of nowhere Wink