void OnDoDamage(ref MyEventDoDamage msg)
        {
            MyEntity target;
            if (MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.TargetEntityId), out target) && CheckSenderId(msg, msg.TargetEntityId))
            {
                MyEntity source;
                if (!msg.DamageSource.HasValue || !MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.DamageSource.Value), out source))
                {
                    source = null;
                }

                Debug.Assert(target.IsDummy);
                target.IsDummy = false;
                // This is stupid, but necessary, DoDamage should be fixed
                if (msg.NewHealthRatio <= 0)
                {
                    target.HealthRatio = 0.0001f;
                    target.DoDamage(msg.PlayerDamage, msg.Damage, msg.EmpDamage, (MyDamageType)msg.DamageType, (MyAmmoType)msg.AmmoType, source);

                    //Closes entity 
                    target.UpdateBeforeSimulation();
                }
                else
                {
                    target.HealthRatio = 100.0f;
                    target.DoDamage(msg.PlayerDamage, msg.Damage, msg.EmpDamage, (MyDamageType)msg.DamageType, (MyAmmoType)msg.AmmoType, source);
                    target.HealthRatio = msg.NewHealthRatio;
                }
                target.IsDummy = true;
            }
            else
            {
                Alert("Call 'OnDamage' on invalid entity", msg.SenderEndpoint, msg.EventType);
            }
        }
 public void DoDamage(MyEntity target, float player, float normal, float emp, MyDamageType damageType, MyAmmoType ammoType, MyEntity source, float newHealthRatio)
 {
     if (IsControlledByMe(target))
     {
         MyEventDoDamage msg = new MyEventDoDamage();
         msg.TargetEntityId = target.EntityId.Value.NumericValue;
         msg.PlayerDamage = player;
         msg.Damage = normal;
         msg.EmpDamage = emp;
         msg.DamageType = (byte)damageType;
         msg.AmmoType = (byte)ammoType;
         msg.DamageSource = source != null ? MyEntityIdentifier.ToNullableInt(source.EntityId) : null;
         msg.NewHealthRatio = newHealthRatio;
         Peers.SendToAll(ref msg, NetDeliveryMethod.ReliableUnordered);
     }
 }