Frictional Games Forum (read-only)
I need help with creating more than 1 scripts for my custom story - 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: I need help with creating more than 1 scripts for my custom story (/thread-18533.html)

Pages: 1 2


RE: I need help with creating more than 1 scripts for my custom story - ironman0001 - 09-28-2012

(09-28-2012, 05:08 AM)Statyk Wrote: No, all your scripts start from there. You should never have more than one OnStart, OnLeave, or OnEnter.
Well i played one custom story and it has alot of scripts and i only see void OnStart. Here is the script: void OnStart()
{
AddUseItemCallback("", "key_1", "level_wood_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "ScriptArea_1", "Scary_1", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_2", "Scary_2", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_3", "Scary_3", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_4", "Scary_4", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_5", "Scary_5", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_6", "Scary_6", true, 1);
SetEntityPlayerInteractCallback("key_1", "Pickup_1", true);
SetEntityPlayerInteractCallback("key_study_1", "Pickup_2", true);
SetEntityPlayerInteractCallback("key_study_2", "Pickup_3", true);
SetEntityPlayerInteractCallback("key_study_3", "Pickup_4", true);
SetEntityPlayerInteractCallback("note1", "ReadPaper", true);
AddUseItemCallback("", "knife", "blocker2", "cuttertask", true);
AddUseItemCallback("", "dolch", "gruntmonster", "kill1", true);
AddUseItemCallback("", "key_study_1", "door1", "d1", true);
AddUseItemCallback("", "key_study_2", "door2", "d2", true);
AddUseItemCallback("", "key_study_3", "door3", "d3", true);
AddUseItemCallback("", "key_study_4", "door4", "d4", true);
SetPlayerLampOil(0.0f);
}

void Scary_6(string &in asEntity)
{
SetMessage("Messages", "text1", 5);
}

void kill1(string &in asItem, string &in asEntity)
{
GiveSanityBoostSmall();
PlaySoundAtEntity("", "attack_claw.snt", "Player", 0, false);
PlaySoundAtEntity("", "attack_claw_hit.snt", "Player", 0, false);
SetEntityActive("gruntmonster", false);
}

void d1(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door1", false, true);
PlaySoundAtEntity("", "unlock_door", "d1", 0, false);
RemoveItem("key_study_1");
}

void d2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door2", false, true);
PlaySoundAtEntity("", "unlock_door", "d2", 0, false);
RemoveItem("key_study_2");
}

void d3(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door3", false, true);
PlaySoundAtEntity("", "unlock_door", "d3", 0, false);
RemoveItem("key_study_3");
}

void d4(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("door4", false, true);
PlaySoundAtEntity("", "unlock_door", "d4", 0, false);
RemoveItem("key_study_4");
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetLevelDoorLocked("level_wood_1", false);
PlaySoundAtEntity("", "unlock_door", "level_wood_1", 0, false);
RemoveItem("key_1");
}

void cuttertask(string &in asItem, string &in asEntity)
{
SetEntityActive("sewer_grate_broken_1", true);
PlaySoundAtEntity("", "pickaxe_hit.snt", "Player", 0, false);
SetEntityActive("sewer_grate_new_1", false);
SetEntityActive("blocker2", false);
GiveSanityBoostSmall();
}

void Scary_1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt1", true);
AddPropImpulse("grunt1", -20, 0, 0, "world");
}

void Scary_2(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "enabled.snt", "Player", 0, false);
}

void Scary_3(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("gay1", true);
SetEntityActive("gay2", true);
SetEntityActive("gay3", true);
AddPropImpulse("gay1", -20, 0, -20, "world");
AddPropImpulse("gay2", -20, 0, -20, "world");
AddPropImpulse("gay3", -20, 0, -20, "world");
PlaySoundAtEntity("", "21_screams.snt", "Player", 0, false);
SetEntityActive("key_study_1", true);
}

void Scary_4(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("breaker", false);
SetEntityActive("breaker2", true);
AddPropImpulse("breaker2", 0, 0, -30, "world");
PlaySoundAtEntity("", "break_wood.snt", "Player", 0, false);
PlaySoundAtEntity("", "break_wood.snt", "Player", 0, false);
PlaySoundAtEntity("", "break_wood.snt", "Player", 0, false);
PlaySoundAtEntity("", "amb_alert.snt", "Player", 0, false);
}

void Scary_5(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("corpse_male_1", true);
PlaySoundAtEntity("", "24_iron_maiden.snt", "Player", 0, false);
AddPropImpulse("corpse_male_1", 0, 0, -20, "world");
}

void Pickup_1(string &in asEntity)
{
SetEntityActive("gruntmonster", true);
GiveSanityDamage(5.0f, true);
}

void Pickup_2(string &in asEntity)
{
PlaySoundAtEntity("", "04_warn.snt", "Player", 0, false);
}

void Pickup_3(string &in asEntity)
{
SetEntityActive("ScriptArea_5", true);
SetEntityActive("breaker3", true);
PlaySoundAtEntity("", "break_stairs.snt", "Player", 0, false);
}

void Pickup_4(string &in asEntity)
{
SetEntityActive("hanging_prisoner_1", true);
SetEntityActive("hanging_prisoner_2", true);
SetEntityActive("hanging_prisoner_3", true);
SetEntityActive("hanging_prisoner_4", true);
SetEntityActive("hanging_prisoner_5", true);
SetEntityActive("hanging_prisoner_6", true);
SetEntityActive("hanging_prisoner_7", true);
SetEntityActive("hanging_prisoner_8", true);
SetEntityActive("hanging_prisoner_9", true);
SetEntityActive("hanging_prisoner_10", true);
PlaySoundAtEntity("", "ui_insanity_touch.snt", "Player", 0, false);
}

void Timer_1(string &in asTimer)
{
SetEntityActive("John1", false);
GiveSanityDamage(5.0f, true);
}

void Timer_2(string &in asTimer)
{
GivePlayerDamage(10, "BloodSplat", true, false);
PlaySoundAtEntity("", "hit_wood.snt", "Player", 0, false);
}

void ReadPaper(string& asName)
{
SetEntityPlayerInteractCallback("note1","", true);
}


RE: I need help with creating more than 1 scripts for my custom story - Statyk - 09-28-2012

yes, notice how all the collide callbacks are given in the OnStart? This is where you set up scripts. Anything that is called from those scripts is placed outside. For example:
Spoiler below!

void OnStart()
{
AddUseItemCallback("", "key_1", "level_wood_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "ScriptArea_1", "Scary_1", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_2", "Scary_2", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_3", "Scary_3", true, 1);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
/functions
}

void Scary_1(string &in asParent, string &in asChild, int alState)
{
//functions
}

void Scary_2(string &in asParent, string &in asChild, int alState)
{
//functions
}

void Scary_3(string &in asParent, string &in asChild, int alState)
{
//functions
}



Notice how the callbacks are given when the player walks into a script area or uses a key on a door, and are preset in the OnStart? For example, in a sentence, it would read something like this:

"When the game starts ( void OnStart() ), add a collide callback (AddEntityCollideCallback) so when the player walks into ScriptArea_1 (AddEntityCollideCallback("Player", "ScriptArea_1", ...), it will run THIS function (..."Scary_1")."

Then true says the callback will be removed, so this function will not happen again after it happens once, and the 1 stands for being activated when the player walks into the area. -1 is leaving, and 0 is both. When the player walks into ScriptArea_1, void Scary_1 will activate and the functions inside Scary_1 will run.


RE: I need help with creating more than 1 scripts for my custom story - ironman0001 - 09-28-2012

(09-28-2012, 05:39 AM)Statyk Wrote: yes, notice how all the collide callbacks are given in the OnStart? This is where you set up scripts. Anything that is called from those scripts is placed outside. For example:
Spoiler below!

void OnStart()
{
AddUseItemCallback("", "key_1", "level_wood_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "ScriptArea_1", "Scary_1", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_2", "Scary_2", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_3", "Scary_3", true, 1);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
/functions
}

void Scary_1(string &in asParent, string &in asChild, int alState)
{
//functions
}

void Scary_2(string &in asParent, string &in asChild, int alState)
{
//functions
}

void Scary_3(string &in asParent, string &in asChild, int alState)
{
//functions
}



Notice how the callbacks are given when the player walks into a script area or uses a key on a door, and are preset in the OnStart? For example, in a sentence, it would read something like this:

"When the game starts ( void OnStart() ), add a collide callback (AddEntityCollideCallback) so when the player walks into ScriptArea_1 (AddEntityCollideCallback("Player", "ScriptArea_1", ...), it will run THIS function (..."Scary_1")."

Then true says the callback will be removed, so this function will not happen again after it happens once, and the 1 stands for being activated when the player walks into the area. -1 is leaving, and 0 is both. When the player walks into ScriptArea_1, void Scary_1 will activate and the functions inside Scary_1 will run.
Omg! I finally got it! :D So the commands on the void onstart are there to help you make more voids? Because i tried the "SetMessage("Messages", "Popup1", 0); " And i replaced the void OnEnter () with void Popup1 And it worked! Thanks for all the help! :D


RE: I need help with creating more than 1 scripts for my custom story - FlawlessHappiness - 09-28-2012

You'll need to see a tutorial about scripting.


RE: I need help with creating more than 1 scripts for my custom story - Statyk - 09-28-2012

Agreed, I was simply covering the basics. =P