Hytale Modding
NPC Documentation

5 - NPC Sleep Behavior

Official Hytale Documentation
All content on this section is provided by Hypixel Studios Canada Inc. and is presented without any substantial changes, aside from visual design adjustments by the HytaleModding Team.

Let's add a new top level Sleep state. For illustrative purposes, the Idle state has been truncated.

{
	"Sensor": {
		"Type": "State",
		"State": "Idle"
	},
	"Instructions": [ ... ],
},
{
	"Sensor": {
		"Type": "State",
		"State": "Sleep"
	},
	"Instructions": [ ... ]
}

And now we add another action to the Random action list to move to the Sleep state.

{
  "Sensor": {
    "Type": "State",
    "State": ".Default"
  },
  "Instructions": [
    {
      "Actions": [
        {
          "Type": "Random",
          "Actions": [
            {
              "Weight": 80,
              "Action": {
                "Type": "State",
                "State": ".Guard"
              }
            },
            {
              "Weight": 20,
              "Action": {
                "Type": "State",
                "State": "Sleep"
              }
            }
          ]
        }
      ]
    }
  ]
}

Notice the weights in this case - there's a 20% chance that the ogre will go to sleep any time it decides to switch behaviour, but an 80% chance that it'll just keep standing guard instead.

We still need to actually add the sleeping behaviour, but first we'll add Instruction with the Timeout action to the beginning of the Sleep state, just like we did with .Guard. We just remove "Continue": true because we only have one instruction.