Frictional Games Forum (read-only)
Help what is wrong in my 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Help what is wrong in my script (/thread-12119.html)



Help what is wrong in my script - EpicLisbe - 12-27-2011

So i am working on a customstory project and when i use key_1 it also unlocks the prisondoor can you help me?


void OnStart()
{
AddUseItemCallback("", "key_1", "monsterdoor_1", "UsedKeyOnDoor", true);
SetEntityCallbackFunc("key_1", "OnPickup");
AddEntityCollideCallback("Player", "Scriptarea_1", "func_bam", true, 1);
AddUseItemCallback("", "rust_1", "prisondoor_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "PlayerCollide", "MonsterFunction", true, 1);
AddEntityCollideCallback("Player", "banish", "BanishFunction", true, 1);

}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("monsterdoor_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "monsterdoor_1", 0, false);
RemoveItem("key_1");


}
void OnPickup(string &in asEntity, string &in type)
{
SetEntityActive("servant_grunt_1", true);
ShowEnemyPlayerPosition("servant_grunt_1");
SetSwingDoorLocked("prisondoor_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "prisondoor_1", 0, false);

}


void func_bam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("monsterdoor_1", true, true);
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
PlaySoundAtEntity("", "react_scare", "Player", 0, false);
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
GiveSanityDamage(5.0f, true);
}






void MonsterFunction(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("servant_grunt_2", true);
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_1", 2, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_3", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_4", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_5", 0, "");

}
void BanishFunction(string &in asParent, string &in asChild, int alState)

{
SetEnemyDisabled("servant_grunt_2", true);
SetEntityActive("servant_grunt_2", false);
}




RE: Help what is wrong in my script - Your Computer - 12-27-2011

It doesn't unlock when you use the key, it unlocks when you pick up the key.


RE: Help what is wrong in my script - EpicLisbe - 12-28-2011

(12-27-2011, 09:28 PM)Your Computer Wrote: It doesn't unlock when you use the key, it unlocks when you pick up the key.
can you show me the right script because i am amateur scripter and i think its not unlocking when i pickup because the rust_1 is supposed to unlock prisondoor not key_1.



RE: Help what is wrong in my script - Your Computer - 12-28-2011

(12-28-2011, 12:35 AM)EpicLisbe Wrote: can you show me the right script because i am amateur scripter and i think its not unlocking when i pickup because the rust_1 is supposed to unlock prisondoor not key_1.

Well, this is what you did that makes picking up the key unlock the prisondoor:

You set a callback to "key_1" with SetEntityCallbackFunc in OnStart; the callback being OnPickup. SetEntityCallbackFunc calls the callback when interacting with the item specified. Therefore upon interacting with the key, in this case picking up the key, the callback, OnPickup, gets called.

If we look inside the OnPickup function, we see SetSwingDoorLocked("prisondoor_1", false, true). You passed in false for the second argument. This tells the game to unlock the door called "prisondoor_1". So, all the player has to do is interact with "key_1" in order to unlock the door "prisondoor_1".

The only way to correct your code is for you to understand what you are telling the game to do. This requires understanding of every function you are making use of, starting with OnStart. You can read the descriptions of most of the other functions used here: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions That should at least provide you with basic understanding of their use.


RE: Help what is wrong in my script - EpicLisbe - 12-28-2011

(12-28-2011, 01:02 AM)Your Computer Wrote:
(12-28-2011, 12:35 AM)EpicLisbe Wrote: can you show me the right script because i am amateur scripter and i think its not unlocking when i pickup because the rust_1 is supposed to unlock prisondoor not key_1.

Well, this is what you did that makes picking up the key unlock the prisondoor:

You set a callback to "key_1" with SetEntityCallbackFunc in OnStart; the callback being OnPickup. SetEntityCallbackFunc calls the callback when interacting with the item specified. Therefore upon interacting with the key, in this case picking up the key, the callback, OnPickup, gets called.

If we look inside the OnPickup function, we see SetSwingDoorLocked("prisondoor_1", false, true). You passed in false for the second argument. This tells the game to unlock the door called "prisondoor_1". So, all the player has to do is interact with "key_1" in order to unlock the door "prisondoor_1".

The only way to correct your code is for you to understand what you are telling the game to do. This requires understanding of every function you are making use of, starting with OnStart. You can read the descriptions of most of the other functions used here: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions That should at least provide you with basic understanding of their use.
TY SO MUCH. never tought it would be so easy! Shy





RE: Help what is wrong in my script - EpicLisbe - 12-30-2011

Now i got my .lang file fail Blush can you tell me what is wrong in it <LANGUAGE>

<CATEGORY Name="Inventory">
<Entry Name="ItemName_key1">a scary key</Entry>
<Entry Name="ItemDesc_key1">nice key and you are supposed to use it to a door.</Entry>
<Entry Name="ItemName_Crowbar">A crowbar</Entry
<Entry Name="ItemName_Crowbar">You can use this to break a lock from a door.</Entry>

</CATEGORY>

<CATEGORY Name="Journal">
<Entry Name="Note_theletter_Name">Letter from unknown</Entry>
<Entry Name="Note_theletter_Text">Hello, Daniel.[br]You know you shouldn't mess up with my investigation[br]ps. you might have some hallucinations because of my potion.</Entry>
<Entry Name="Note_thewarning_name"> warning from unknown</Entry>
<Entry Name="Note_thewarning_Text">Hello again daniel.[br][br]You have reached my dungeons where i have done tests with human bodies. I recommend you to avoid the bodies because they might still be alive....</Entry>
<Entry Name="Note_thetest_Name">My test diary page.</Entry>
<Entry Name="Note_thetest_Text">It's 14th may 3:00 Pm.[br][br]I woke up to reality and i understood that i have to finish this and get back to home![br]Tomorrow i do final test if it fails.. well... then WE ALL DIE</Entry>

</CATEGORY>

</LANGUAGE>



RE: Help what is wrong in my script - Apjjm - 12-30-2011

You are missing a closing ">" on one of your entry tags. If you get lang file problems a good website to visit is:

http://www.w3schools.com/xml/xml_validator.asp

Fixed code:
http://pastebin.com/xX3HUtWR


RE: Help what is wrong in my script - EpicLisbe - 12-31-2011

(12-30-2011, 03:27 PM)Apjjm Wrote: You are missing a closing ">" on one of your entry tags. If you get lang file problems a good website to visit is:

http://www.w3schools.com/xml/xml_validator.asp

Fixed code:
http://pastebin.com/xX3HUtWR
TY Shy