AFK Detector

recipe

AFK Detector Animation Controller

Learn more about Animation Controllers

Here's an example that can be used to track AFK players.

BP/animation_controllers/afk.ac.jsonCopy
json
{
	"format_version": "1.10.0",
	"animation_controllers": {
		"controller.animation.player.afk": {
			"states": {
				"default": {
					"transitions": [
						{
							"stands_still": "!q.is_moving"
						}
					]
				},
				"stands_still": {
					"on_entry": [
							"v.afk = q.life_time;"
					],
					"transitions": [
						{
							"afk": "(q.life_time - v.afk) >= 30 && !q.is_moving"
						},
						{
							"default": "q.is_moving"
						}
					]
				},
				"afk": {
					"on_entry": ["/tag @s add AFK", "/say I'm now AFK"],
					"animations": ["afk_animation"],
					"transitions": [
						{
							"default": "q.is_moving"
						}
					],
					"on_exit": ["/tag @s remove AFK", "/say I'm no longer AFK"]
				}
			}
		}
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  • "controller.animation.player.afk" is, of course, the identifier.
  • If the Molang query !q.is_moving returns false (the player isn't moving), the state transits to the "stand_still" state.
  • "stand_still" state checks if player doesn't move in 30 seconds to transmit to "afk", if not return to "default"
  • When the state "afk" gets entered, "on_entry" gets triggered, which runs the following slash commands.
  • "animations" includes the Behavior Animation's shortname that is to be ran during the whole time the state is active, just like in Resource Animation Controllers.
  • If the player is moving again, the state will transit to "default" again. The commands "on_exit" will be executed.

Contributors

SirLich