HyperScript
Docs

← All of the Docs More

Combat and being away

condition<who> is in combatsince 1.7.50

They hit another player, or were hit by one, in the last 15 seconds

command /spawn:
    trigger:
        if player is in combat:
            send "&cNot while you are fighting."
            stop
        teleport player to spawn of world "world" after 3 seconds unless they move
Try it
condition<who> is afksince 1.7.50

They have done nothing for 5 minutes: not moved, looked around, clicked, chatted or run a command

for each {_name} in server.players:
    if {_name} is afk:
        send "&7%{_name}% is away."
Try it
expressionput <who> in combatsince 1.7.50

Count them as fighting from now, as if they had been hit. for 30 seconds to say how long

put player in combat for 30 seconds
Try it
expressiontake <who> out of combatsince 1.7.50

The fight is over for them now

take player out of combat
Try it
effectteleport <who> to <location> after <duration>since 1.7.50

Take them there once that time is over; it counts down on their action bar

teleport player to spawn of world "world" after 3 seconds
Try it
effectteleport <who> to <location> after <duration> unless they movesince 1.7.50

The same, called off if they walk away meanwhile

teleport player to spawn of world "world" after 5 seconds unless they move
Try it
Guide and examples

HyperScript keeps track of two things about every player by itself, so that a script only has to ask.

SyntaxMeaning
<who> is in combatThey hit another player, or were hit by one, in the last 15 seconds
<who> is afkThey have done nothing for 5 minutes: not moved, looked around, clicked, chatted or run a command
put <who> in combatCount them as fighting from now, as if they had been hit. for 30 seconds to say how long
take <who> out of combatThe fight is over for them now
teleport <who> to <location> after <duration>Take them there once that time is over; it counts down on their action bar
teleport <who> to <location> after <duration> unless they moveThe same, called off if they walk away meanwhile
command /spawn:
    trigger:
        if player is in combat:
            send "&cNot while you are fighting."
            stop
        teleport player to spawn of world "world" after 5 seconds unless they move

on combat start:
    send action bar "&cIn combat with %event.opponent%" to player while player is in combat

on player quit:
    if player is in combat:
        broadcast "&c%player.name% logged out in a fight."

on afk:
    broadcast "&7%player.name% is away."
  • Both times are in config.yml: combat-time: "15s" and afk-time: "5m". 0 switches one off.
  • A fight is between players. A mob does not put anybody in combat; put victim in combat in on entity damage: does, if you want that.
  • on combat start: runs once when a fight begins, not at every hit, and on combat end: when it is over. %event.opponent% is who the fight is with.
  • on afk: and on afk return: run when a player goes away and comes back. Turning the head counts as doing something; being pushed along by water does not.
  • What a waiting teleport says is in config.yml under messages:, and can be changed or left empty. A second teleport ... after for the same player takes the place of the first.