bool IsNight() { GameClock.TimeBlock TimeBlock = GameClock.Instance.CurrentTimeBlock; if (TimeBlock != GameClock.TimeBlock.Dusk && TimeBlock != GameClock.TimeBlock.Night) { return(false); } if (TimeBlock == GameClock.TimeBlock.Dusk && GetCurrentHour() < 21) { return(false); } return(true); }
private void OnEntityHealthChange(EntityDamageEvent damageEvent) { GameClock.TimeBlock TimeBlock = GameClock.Instance.CurrentTimeBlock; if ( damageEvent.Damage.Amount > 0 && // taking damage damageEvent.Entity.IsPlayer && // entity taking damage is player damageEvent.Damage.DamageSource.IsPlayer && // entity delivering damage is a player damageEvent.Entity != damageEvent.Damage.DamageSource && // entity taking damage is not taking damage from self !IsNight() // Not night time ) { damageEvent.Cancel("Can Only Kill At Night"); damageEvent.Damage.Amount = 0f; PrintToChat(damageEvent.Damage.DamageSource.Owner, "[FF0000]You can only attack other players at night.[FFFFFF]"); } }