Malus Black
Junior Member
Posts: 2
Threads: 1
Joined: May 2013
Reputation:
0
|
[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
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
(This post was last modified: 05-18-2013, 03:18 PM by Malus Black.)
|
|
05-18-2013, 03:18 PM |
|
OriginalUsername
Posting Freak
Posts: 896
Threads: 42
Joined: Feb 2013
Reputation:
34
|
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.
void OnStart() { AddEntityCollideCallback("Scriptarea1", "Player", "Starttimer", true, 0); }
void Starttimer(string &in asParent, string &in asChild, int 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?
|
|
05-18-2013, 03:39 PM |
|
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
|
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:
if(GetPlayerHealth() < 99 or whatever)
|
|
05-18-2013, 04:12 PM |
|
Adrianis
Senior Member
Posts: 620
Threads: 6
Joined: Feb 2012
Reputation:
27
|
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 |
|
ClayPigeon
Member
Posts: 214
Threads: 13
Joined: Mar 2012
Reputation:
8
|
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 |
|
OriginalUsername
Posting Freak
Posts: 896
Threads: 42
Joined: Feb 2013
Reputation:
34
|
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.
|
|
05-18-2013, 11:35 PM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
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.
(This post was last modified: 05-18-2013, 11:56 PM by Your Computer.)
|
|
05-18-2013, 11:55 PM |
|
OriginalUsername
Posting Freak
Posts: 896
Threads: 42
Joined: Feb 2013
Reputation:
34
|
RE: [SCRIPT] Running a script when attacked
I actually feel stupid now.
|
|
05-19-2013, 12:33 AM |
|
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
|
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 |
|
Malus Black
Junior Member
Posts: 2
Threads: 1
Joined: May 2013
Reputation:
0
|
RE: [SCRIPT] Running a script when attacked
Thanks, guys It seems to work fine.
|
|
05-20-2013, 01:39 PM |
|
|