Frictional Games Forum (read-only)
[SCRIPT] Running a script when attacked - 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] Running a script when attacked (/thread-21534.html)



[SCRIPT] Running a script when attacked - Malus Black - 05-18-2013

Hi, everyone. I'm currently working on my very first Custom Story, and although I've got the basics of scripting down, I have come to a situation where I have no idea what to do and so hope you guys might help out Smile

In short, I've got an area where I want two grunts to come chasing after the player, and when he gets hit I want to run a script. I'm also open for any sort of cheating workarounds if that's impossible to do Wink


RE: [SCRIPT] Running a script when attacked - OriginalUsername - 05-18-2013

You could run a timer checking if the player health is lower than 99. But before the player enters the area you have to make sure he has more than 99 health. (That means 100). It won't be exactly when the player's hit, but it's close.

PHP Code:
void OnStart()
{
AddEntityCollideCallback("Scriptarea1""Player""Starttimer"true0);
}

void Starttimer(string &in asParentstring &in asChildint alState)
{
AddTimer(""1"starttimer2");
SetPlayerHealth(100);
}

void starttimer2(string &in asTimer)
{
AddTimer("timer2"1"starttimer3");
checkhealth();
}

void starttimer3(string &in asTimer)
{
AddTimer("timer1"1"starttimer2");
checkhealth();
}

void checkhealth()
{
if(
GetPlayerHealth(<100))
{
//Do whatever you want
RemoveTimer("timer1");
RemoveTimer("timer2");
}


I'm not sure if the getplayerhealth is right, could someone tell me/us if it is?


RE: [SCRIPT] Running a script when attacked - Tomato Cat - 05-18-2013

(05-18-2013, 03:39 PM)Smoke Wrote: I'm not sure if the getplayerhealth is right, could someone tell me/us if it is?

I don't think it takes any arguments.
Try doing this:

PHP Code:
if(GetPlayerHealth() < 99 or whatever



RE: [SCRIPT] Running a script when attacked - Adrianis - 05-18-2013

If you do do it like that, you'll need to make absolutely sure that the player can't take any damage from any other source, like falling...


RE: [SCRIPT] Running a script when attacked - ClayPigeon - 05-18-2013

Try setting the player's health to enourmous numbers before the hit.
Set up an area before the hit, when which he collides with, it sets his health to lets say... a billion, and another area on the actual floor, and when he hits it, it sets his health back to 100.
Not sure if the engine allows to set over 100 hp, though.


RE: [SCRIPT] Running a script when attacked - OriginalUsername - 05-18-2013

(05-18-2013, 11:17 PM)ClayPigeon Wrote: Try setting the player's health to enourmous numbers before the hit.
Set up an area before the hit, when which he collides with, it sets his health to lets say... a billion, and another area on the actual floor, and when he hits it, it sets his health back to 100.
Not sure if the engine allows to set over 100 hp, though.

I think I fixed that already. I set the player's health to 100 when the timers start to run. Just make sure the player can't take any other damage than the monster's.


RE: [SCRIPT] Running a script when attacked - Your Computer - 05-18-2013

Code:
AddEntityCollideCallback("Player", "name_of_monster", "Callback", true, 1);

There's no need to check if the player has lost health.


RE: [SCRIPT] Running a script when attacked - OriginalUsername - 05-19-2013

I actually feel stupid now.


RE: [SCRIPT] Running a script when attacked - Tomato Cat - 05-19-2013

(05-18-2013, 11:55 PM)Your Computer Wrote:
Code:
AddEntityCollideCallback("Player", "name_of_monster", "Callback", true, 1);

There's no need to check if the player has lost health.

Oh. That counts as a collision?


RE: [SCRIPT] Running a script when attacked - Malus Black - 05-20-2013

Thanks, guys Smile It seems to work fine.