Frictional Games Forum (read-only)
asAtTargetCallback??? - 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: asAtTargetCallback??? (/thread-19949.html)



asAtTargetCallback??? - reper1210 - 01-16-2013

what do i write for this?
asAtTargetCallback - function to call when player looks at target

this is the code i need to write it in.

void StartPlayerLookAt(string& asEntityName, float afSpeedMul, float afMaxSpeed, string& asAtTargetCallback);
void StopPlayerLookAt();

and this is what i have for it so far.

StartPlayerLookAt(string& mansion_door_1, 20, 20, string& asAtTargetCallback);
StopPlayerLookAt(3);


RE: asAtTargetCallback??? - str4wberrypanic - 01-16-2013

AtTargetCallback is a function that happens when the player looks at the entity or area you want him to look. Anyway, if you don't want to use this, just leave this way:

StartPlayerLookAt(string& mansion_door_1, 20, 20, "");



And i think you will need to use a timer in this script.


RE: asAtTargetCallback??? - reper1210 - 01-16-2013

(01-16-2013, 04:00 AM)str4wberrypanic Wrote: AtTargetCallback is a function that happens when the player looks at the entity or area you want him to look. Anyway, if you don't want to use this, just leave this way:

StartPlayerLookAt(string& mansion_door_1, 20, 20, "");



And i think you will need to use a timer in this script.

it crashed my game when i entered that in. game worked fine before so can i put the code in like this?

void OnStart()
{
GiveItemFromFile("lantern", "lantern.ent");
SetEntityPlayerInteractCallback("key_laboratory_1", "ActivateMonster", true);
AddUseItemCallback("OpenDoor", "key_laboratory_1", "level_hub_1", "UnlockLevelDoor", true);
}

void OnEnter()
{

}

void OnLeave()
{

}

void ActivateMonster(string &in item)
{
StartPlayerLookAt(string& mansion_door_1, 20, 20, "");
StopPlayerLookAt(3);
SetEntityActive("servant_brute_1", true);
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_1", 0, "Idle");
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_2", 0, "Idle");
}

void UnlockLevelDoor(string &in item, string &in entity)
{
SetLevelDoorLocked(entity, false);


RE: asAtTargetCallback??? - NaxEla - 01-16-2013

PHP Code:
void OnStart()
{
GiveItemFromFile("lantern""lantern.ent");
SetEntityPlayerInteractCallback("key_laboratory_1""ActivateMonster"true);
AddUseItemCallback("OpenDoor""key_laboratory_1""level_hub_1""UnlockLevelDoor"true);
}

void OnEnter()
{

}

void OnLeave()
{

}

void ActivateMonster(string &in item)
{
StartPlayerLookAt("mansion_door_1"2020"");   // changed this line
StopPlayerLookAt();   // changed this line also
SetEntityActive("servant_brute_1"true);
AddEnemyPatrolNode("servant_brute_1""PathNodeArea_1"0"Idle");
AddEnemyPatrolNode("servant_brute_1""PathNodeArea_2"0"Idle");
}

void UnlockLevelDoor(string &in itemstring &in entity)
{
SetLevelDoorLocked(entityfalse); 

The way your script is set up right now, the player will look at the door, then instantly stop looking at it (the player's eyes may not even make it to the door). I would suggest adding a timer so that the player will stop looking after a certain amount of time.

One more thing. In this line:
PHP Code:
StartPlayerLookAt("mansion_door_1"2020""); 
You can modify the values (20, 20 in this case) to different values. The lower the number, the slower the player will look.


RE: asAtTargetCallback??? - reper1210 - 01-16-2013

thanks for the help, it didn't crash my game this time but i guess i do need a timer. how would that go into my script? and where?


RE: asAtTargetCallback??? - NaxEla - 01-16-2013

(01-16-2013, 06:00 AM)reper1210 Wrote: thanks for the help, it didn't crash my game this time but i guess i do need a timer. how would that go into my script? and where?

Taken from the wiki:

PHP Code:
void AddTimer(stringasNamefloat afTimestringasFunction); 
Creates a timer which calls a function when it expires.
Callback syntax: void MyFunc(string &in asTimer)

asName - the name of the timer
afTime - time in seconds
asFunction - the function to call

So you would put this after the StartPlayerLookAt line:
PHP Code:
AddTimer(""3"StopLookingFunc"); // you can change '3' to whatever number you like 
Then make a new function called "StopLookingFunc" that looks like this:
PHP Code:
void StopLookingFunc(string &in asTimer)
{
    
StopPlayerLookAt();