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


Messages In This Thread
RE: how can i teleport a player when hit by an enemy - by Mudbill - 02-08-2014, 10:48 PM



Users browsing this thread: 1 Guest(s)