Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SCRIPT] Running a script when attacked
Malus Black Offline
Junior Member

Posts: 2
Threads: 1
Joined: May 2013
Reputation: 0
#1
[SCRIPT] Running a script when attacked

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
(This post was last modified: 05-18-2013, 03:18 PM by Malus Black.)
05-18-2013, 03:18 PM
Find
OriginalUsername Offline
Posting Freak

Posts: 896
Threads: 42
Joined: Feb 2013
Reputation: 34
#2
RE: [SCRIPT] Running a script when attacked

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: (Select All)
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?
(This post was last modified: 05-18-2013, 04:01 PM by OriginalUsername.)
05-18-2013, 03:39 PM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#3
RE: [SCRIPT] Running a script when attacked

(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: (Select All)
if(GetPlayerHealth() < 99 or whatever
05-18-2013, 04:12 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#4
RE: [SCRIPT] Running a script when attacked

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...

05-18-2013, 07:01 PM
Find
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#5
RE: [SCRIPT] Running a script when attacked

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.
05-18-2013, 11:17 PM
Find
OriginalUsername Offline
Posting Freak

Posts: 896
Threads: 42
Joined: Feb 2013
Reputation: 34
#6
RE: [SCRIPT] Running a script when attacked

(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.
(This post was last modified: 05-18-2013, 11:36 PM by OriginalUsername.)
05-18-2013, 11:35 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#7
RE: [SCRIPT] Running a script when attacked

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

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

Tutorials: From Noob to Pro
(This post was last modified: 05-18-2013, 11:56 PM by Your Computer.)
05-18-2013, 11:55 PM
Website Find
OriginalUsername Offline
Posting Freak

Posts: 896
Threads: 42
Joined: Feb 2013
Reputation: 34
#8
RE: [SCRIPT] Running a script when attacked

I actually feel stupid now.
05-19-2013, 12:33 AM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#9
RE: [SCRIPT] Running a script when attacked

(05-18-2013, 11:55 PM)Your Computer Wrote:
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?
05-19-2013, 05:11 AM
Find
Malus Black Offline
Junior Member

Posts: 2
Threads: 1
Joined: May 2013
Reputation: 0
#10
RE: [SCRIPT] Running a script when attacked

Thanks, guys Smile It seems to work fine.
05-20-2013, 01:39 PM
Find




Users browsing this thread: 3 Guest(s)