using Rust; namespace Oxide.Plugins { [Info("No Vehicle Collision Damage", "bsdinis", "0.1.8")] [Description("Disables collision damage and collision effects for helicopters, submarines, ground vehicles and trains when there are players mounted.")] class NoVehicleCollisionDamage : RustPlugin { const string attackCrashEffect = "d1f0f48f831aa63438cc87b6854aa1d1"; const string miniCrashEffect = "8a5c10cbb6bbb21418ce0a4b305ce87b"; const string scrapCrashEffect = "93d88f022f0be409db6b7c5ec7a3dbbe"; const string subAboveWatercollisionEffect = "191b622de8fecfc49868aed7afd51da9"; const string subUnderWatercollisionEffect = "85b3f969ccea9d444a242434935a15c0"; const string snowmobileCollisionEffect = "ec823dded4359492dba27c72222870e0"; const string modularCarCollisionEffect = "12776bb7ac9660144b72649ffc963c59"; const string trainCollisionEffect = "f3532bcec81a3fc499f310d0124fe4f6"; void OnServerInitialized() { foreach (BaseNetworkable entity in BaseNetworkable.serverEntities) { PlayerHelicopter heli = entity as PlayerHelicopter; if (heli != null) { if (heli.AnyMounted()) { heli.crashEffect.guid = null; } continue; } BaseSubmarine sub = entity as BaseSubmarine; if (sub != null) { if (sub.AnyMounted()) { sub.aboveWatercollisionEffect.guid = null; sub.underWatercollisionEffect.guid = null; } continue; } GroundVehicle gvehicle = entity as GroundVehicle; if (gvehicle != null) { if (gvehicle.AnyMounted()) { gvehicle.collisionEffect.guid = null; } continue; } TrainCar train = entity as TrainCar; if (train != null) { if (train.AnyMounted()) { train.collisionEffect.guid = null; } continue; } } } void Unload() { foreach (BaseNetworkable entity in BaseNetworkable.serverEntities) { PlayerHelicopter heli = entity as PlayerHelicopter; if (heli != null) { if (heli.ShortPrefabName == "attackhelicopter.entity") { heli.crashEffect.guid = attackCrashEffect; } else if (heli.ShortPrefabName == "minicopter.entity") { heli.crashEffect.guid = miniCrashEffect; } else if (heli.ShortPrefabName == "scraptransporthelicopter") { heli.crashEffect.guid = scrapCrashEffect; } continue; } BaseSubmarine sub = entity as BaseSubmarine; if (sub != null) { sub.aboveWatercollisionEffect.guid = subAboveWatercollisionEffect; sub.underWatercollisionEffect.guid = subUnderWatercollisionEffect; continue; } GroundVehicle gvehicle = entity as GroundVehicle; if (gvehicle != null) { if (gvehicle.ShortPrefabName.EndsWith("snowmobile")) { gvehicle.collisionEffect.guid = snowmobileCollisionEffect; } else if (gvehicle.ShortPrefabName.EndsWith("module_car_spawned.entity")) { gvehicle.collisionEffect.guid = modularCarCollisionEffect; } continue; } TrainCar train = entity as TrainCar; if (train != null) { train.collisionEffect.guid = trainCollisionEffect; continue; } } } void OnEntityMounted(BaseVehicleSeat mount, BasePlayer player) { BaseEntity entity = mount.GetParentEntity(); if (entity == null) { return; } PlayerHelicopter heli = entity as PlayerHelicopter; if (heli != null) { heli.crashEffect.guid = null; return; } BaseSubmarine sub = entity as BaseSubmarine; if (sub != null) { sub.aboveWatercollisionEffect.guid = null; sub.underWatercollisionEffect.guid = null; return; } GroundVehicle snow = entity as GroundVehicle; if (snow != null) { snow.collisionEffect.guid = null; return; } VehicleModuleSeating moduleSeat = entity as VehicleModuleSeating; if (moduleSeat != null) { GroundVehicle car = moduleSeat.Vehicle as GroundVehicle; if (car != null) { car.collisionEffect.guid = null; } return; } TrainCar train = entity as TrainCar; if (train != null) { train.collisionEffect.guid = null; return; } } void OnEntityDismounted(BaseVehicleSeat mount, BasePlayer player) { BaseEntity entity = mount.GetParentEntity(); if (entity == null) { return; } PlayerHelicopter heli = entity as PlayerHelicopter; if (heli != null) { if (!heli.AnyMounted()) { if (heli.ShortPrefabName == "attackhelicopter.entity") { heli.crashEffect.guid = attackCrashEffect; } else if (heli.ShortPrefabName == "minicopter.entity") { heli.crashEffect.guid = miniCrashEffect; } else if (heli.ShortPrefabName == "scraptransporthelicopter") { heli.crashEffect.guid = scrapCrashEffect; } } return; } BaseSubmarine sub = entity as BaseSubmarine; if (sub != null) { if (!sub.AnyMounted()) { sub.aboveWatercollisionEffect.guid = subAboveWatercollisionEffect; sub.underWatercollisionEffect.guid = subUnderWatercollisionEffect; } return; } GroundVehicle snow = entity as GroundVehicle; if (snow != null) { if (!snow.AnyMounted()) { snow.collisionEffect.guid = snowmobileCollisionEffect; } return; } VehicleModuleSeating moduleSeat = entity as VehicleModuleSeating; if (moduleSeat != null) { GroundVehicle gvehicle = moduleSeat.Vehicle as GroundVehicle; if (gvehicle != null && !gvehicle.AnyMounted()) { gvehicle.collisionEffect.guid = modularCarCollisionEffect; } return; } TrainCar train = entity as TrainCar; if (train != null) { if (!train.AnyMounted()) { train.collisionEffect.guid = trainCollisionEffect; } return; } } object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (!entity.IsValid() || info == null || info.Initiator == null || info.damageTypes == null) { return null; } BaseHelicopter heli = entity as BaseHelicopter; if (heli != null) { if (!(heli is CH47HelicopterAIController) && info.Initiator == heli && info.damageTypes.Has(DamageType.Explosion) && heli.AnyMounted()) { return true; } return null; } BaseSubmarine sub = entity as BaseSubmarine; if (sub != null) { if (info.Initiator == sub && info.damageTypes.Has(DamageType.Collision) && sub.AnyMounted()) { return true; } return null; } Snowmobile snow = entity as Snowmobile; if (snow != null) { if (info.Initiator == snow && info.damageTypes.Has(DamageType.Collision) && snow.AnyMounted()) { return true; } return null; } BaseVehicleModule module = entity as BaseVehicleModule; if (module != null) { if (info.Initiator == module.Vehicle && info.damageTypes.Has(DamageType.Collision) && module.Vehicle.AnyMounted()) { return true; } return null; } TrainCar train = entity as TrainCar; if (train != null) { if (info.Initiator == train && info.damageTypes.Has(DamageType.Collision) && train.AnyMounted()) { return true; } return null; } return null; } } }