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
how can i teleport a player when hit by an enemy
Yoshida Offline
Junior Member

Posts: 3
Threads: 4
Joined: Feb 2014
Reputation: 0
#1
how can i teleport a player when hit by an enemy

how can i teleport a player when hit by an enemy or killed??? The script if u know it
02-08-2014, 09:30 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: how can i teleport a player when hit by an enemy

That might be a little difficult. Perhaps it's possible to add a check for when the enemy collides with the player, although it doesn't guarantee that the player is hit.

If you can make sure the player is not damaged in any other way in the map, you can add a check for whenever the player gets below a certain amount of health. Again, doesn't guarantee that the player is hit, but if you're careful it could certainly seem like it.

For checking when the player is dead, just add a
CheckPoint("checkpoint1", "PlayerStartArea_2", "", "", "");
to your OnStart block, then edit the PlayerStartArea_2 to the area you want him to respawn.

For the collision check, add this to your OnStart block:
AddEntityCollideCallback("Player", "Enemy", "EnemyCollidePlayer", true, 0);

Edit "Enemy" to your enemy name and if you want "EnemyCollidePlayer" to anything you want. Then add something like this outside the OnStart block.

void EnemyCollidePlayer(string &in asParent, string &in asChild, int alState)
{
    TeleportPlayer("PlayerStartArea_2");
}

In there, edit "PlayerStartArea_2" to the area you want to teleport the player to. You might also wanna add some details like fading so it doesn't look so obvious.

For my second suggestion, there are several ways of checking this. One way is to add a looping timer. To do that, add this to OnStart:

TimerLoopCheck("loopcheck");

And add this outside it:
TimerLoopCheck(string &in asTimer)
{
    if(GetPlayerHealth <= 75) {
        TeleportPlayer("PlayerStartArea_2");
        return;
    }
    AddTimer(asTimer, 1f, "TimerLoopCheck");
}

In these you may edit the timer name if you want, though not necessary. Edit the area like above. If you want to edit the amount of health the player must be below, edit the 75 to anything else. Oh, and you can edit the number 1 in the AddTimer line to update the frequency of the timer. Using something like 0.01 will make it pretty much instant.

You could also combine the last two into one to perhaps improve it, I'm just not certain if the enemy entity is actually colliding with the player when it hits him.

I hope this helps. There may be other ways on how to do this that I'm missing.

(This post was last modified: 02-08-2014, 10:57 PM by Mudbill.)
02-08-2014, 10:48 PM
Find
Yoshida Offline
Junior Member

Posts: 3
Threads: 4
Joined: Feb 2014
Reputation: 0
#3
RE: how can i teleport a player when hit by an enemy

ok thx gonna try it
02-09-2014, 01:11 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#4
RE: how can i teleport a player when hit by an enemy

Careful, the function TimerLoopCheck is gonna loop and keep teleporting the player if his health is still <= 75.

02-09-2014, 01:18 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#5
RE: how can i teleport a player when hit by an enemy

(02-09-2014, 01:18 AM)Amn Wrote: Careful, the function TimerLoopCheck is gonna loop and keep teleporting the player if his health is still <= 75.

Well, it actually won't because as soon as the if statement passes (first time at 75 health), return is called which makes it not loop anymore.

02-09-2014, 01:42 AM
Find
Wapez Offline
Senior Member

Posts: 360
Threads: 37
Joined: Mar 2012
Reputation: 19
#6
RE: how can i teleport a player when hit by an enemy

(02-09-2014, 01:42 AM)Mudbill Wrote: Well, it actually won't because as soon as the if statement passes (first time at 75 health), return is called which makes it not loop anymore.

I suggest not running this loop until you spawn the monster, for the sake of performance. Then I'd also change the timer countdown to 0.1 seconds to actually make sure the player is teleported instantly and not after one second.

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
02-09-2014, 02:35 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#7
RE: how can i teleport a player when hit by an enemy

(02-09-2014, 01:42 AM)Mudbill Wrote:
(02-09-2014, 01:18 AM)Amn Wrote: Careful, the function TimerLoopCheck is gonna loop and keep teleporting the player if his health is still <= 75.

Well, it actually won't because as soon as the if statement passes (first time at 75 health), return is called which makes it not loop anymore.
Oh, so the timer below is the only one calling the function.
So it's supposed to work only once? Or you declare the callback again?

02-09-2014, 07:37 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#8
RE: how can i teleport a player when hit by an enemy

(02-09-2014, 07:37 PM)Amn Wrote: Oh, so the timer below is the only one calling the function.
So it's supposed to work only once? Or you declare the callback again?

Yes, the timer only loops if it gets to the AddTimer at the bottom line. It does get there every loop until the if statement returns true, because return; makes it cancel out any further functions.

Of course instead of using return you could put else AddTimer so that it only adds the timer if the if statement returns false.

02-10-2014, 01:53 AM
Find




Users browsing this thread: 2 Guest(s)