using System; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.API.MathTools; namespace driftermod { public class Driftermod : ModSystem { public override void Start(ICoreAPI api) { base.Start(api); api.RegisterEntity("EntityDrifter", typeof(Drifter)); // <--------------- registering, if there is somewere a entity with the EntityDrifter-class } } public class Drifter : EntityAgent // <--------------- The Drifter-class itself { Random r = new Random(); public override void OnEntitySpawn() // <--------------- is called, when the drifter spawns { base.OnEntitySpawn(); if (Pos.Y >= 100) // <--------------- loocks, if the drifter is above the height 100 (you can change it however you want, 200, 300, 50) { if (r.Next(0, 3) != 1) // <--------------- gets a random number from 0, 1, and 2; if it is not 1, than it kills the drifter (you can change the second number to what you want, bigger than 1. 5 is a smaler chance, that the drifter spawns) { Die(EnumDespawnReason.Removed); } else // <--------------- Fixes gliches, when the drifter spawns not alive { AnimManager.StopAnimation("die"); AnimManager.ActiveAnimationsByAnimCode.Clear(); Alive = true; } } } } }