Damage QuestionNo Thanks

Hi there! So I'm wondering if it's possible to make it so when a vehicle is claimed damage dealt by the player is fully disabled, but ofc environment is enabled. But when it's not claimed all damage is enabled? Is this possible, thanks!

There are many potential features that could be added around owned vehicles. Having them all in this plugin would eventually make it very difficult to maintain, so I prefer the modular approach, where each plugin tries to provide a particular functionality with excellence. That allows this plugin to focus only on granting vehicle ownership. There are also many important reasons to keep plugins small and focused but I won't go into them now.

My suggestion would be to implement this in a separate plugin that simply piggybacks off the OwnerID of the vehicle, like quite a few of my other plugins do because it's a simple design. A typical implementation would be to hook when damage is about to be done to the vehicle, and have the plugin block or scale the damage if the damage is being dealt by a player whose steam id matches the vehicle OwnerID.

Here's a rough sketch which I have not tested. It may need a few tweaks to get fully working.

object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
{
    if (entity == null || info == null)
        return null;

    var initiatorPlayer = info.InitiatorPlayer;
    if (initiatorPlayer == null || !initiatorPlayer.userID.IsSteamId())
    {
        // Attacker is not a real player, so don't alter damage.
        return null;
    }

    if (!(entity is BaseVehicle) && !(entity is HotAirBalloon))
    {
        // Entity receiving damage is not a vehicle, so don't alter damage.
        return null;
    }

    if (entity.OwnerID == 0 || entity.OwnerID != initiatorPlayer.userID)
    {
        // Not owned by the player, so don't alter damage.
        return null;
    }

    // At this point, we know it's a real player attacking a vehicle they own, so scale to 0 damage.
    info.damageTypes.ScaleAll(0);

    // Block the damage from being further processed by the game so it doesn't prevent repair for 30 seconds.
    // Returning `true` as opposed to `false` is the standard for object hooks to avoid hook conflicts.
    return true;
}​

 

You'll want to test the following usage cases. If it doesn't work as expected for these cases, the code will need some adjusting but nothing major.
  • Dealing damage to modular cars, since the modules are distinct entities which might receive the damage directly.
  • Dealing damage with projectiles like rockets, grenade launchers and c4.

Ahh awesome! Thank you so much for the detailed response. I don't really have a lot of experience when it comes to actually making Rust plugins. Would this be possible to add into the TruePVE code possibly? This handles damage in a variety of ways for my server you see, and it seemed like Vehicle Ownership overwrited it, which is why I came here today :)

I haven't worked with or use TruePVE, and I'm too busy to get familiar with how it works, so I suggest asking the maintainer of that plugin if this is something that would make sense to add. If not, then you could make a simple plugin with the above code dropped in.

namespace Oxide.Plugins
{
    [Info("Prevent Damage To Own Vehicles", "RocketManKianYT", "1.0.0")]
    [Description("Protects vehicles from being damaged by their owner.")]
    internal class PreventDamageToOwnVehicles : CovalencePlugin
    {
        // 1. Insert the other code here
        // 2. Save this file to oxide/plugins/PreventDamageToOwnVehicles.cs
    }
}
​

This slightly works, but not on everything. On minicopters etceteras it works, but yeah as you mentioned. Not on Modular Cars. 

Merged post

Hopefully the code wouldn't be too hard for you to possibly help me fix :)

Replace the vehicle and ownership checks with this.

var vehicleEntity = entity as BaseVehicle
    ?? entity as HotAirBalloon
    ?? (entity as BaseVehicleModule)?.Vehicle as BaseCombatEntity;

if (vehicleEntity == null)
{
    // Entity receiving damage is not a vehicle, so don't alter damage.
    return null;
}

if (vehicleEntity.OwnerID == 0 || vehicleEntity.OwnerID != initiatorPlayer.userID)
{
    // Not owned by the player, so don't alter damage.
    return null;
}​

Works! Thank you so much :)

Merged post

Hey just wondering, something very weird happened... so once adding this to my server it seems all Horses have just like disappeared... sorta decayed it seems? I also use your Plugin 'Vehicle Decay Protection' alongside this one. Could my plugin overwrite or break anything to do with that?

Merged post

Also on top of this. If I claim the vehicle it stops me from damaging it, but not everyone else. Also doesn't seem to work with minicopters on my main server which is strange. Minicopters are just invulnerable completely no matter whether their claimed or not

This plugin just prevents damage so it cannot block another plugin from preventing damage, so it doesn't explain the missing horses.

If others are able to damage your vehicles, this is likely an issue with TruePVE since it's my understanding that you aren't supposed to be able to damage entities owned by others with that plugin. I saw there was a recent update to it regarding vehicles that might be related.

If you want any owned vehicle to be unmanageable by players, you can remove the code that checks that the owner ID matches the player ID.

Not sure why minicopter would be invulnerable since things like collision damage aren't initiated by a player (I assume), so probably another plugin causing that.

Awesome removing some of that owner id code fixed the other vehicles. Minicopter takes collision damage but not player dealt damage for some weird reason... I don't understand why cause every other vehicle works. I haven't updated TruePVE yet either as it had the same mistake as I had with my plugin when it doesn't affect vehicles

I'm confused about your request. It sounded like you originally wanted to prevent players from damaging owners vehicles, unless they were the owner, so that's the code I provided. Then it turns out you want to prevent any player from damaging an owned vehicle, so I told you how to make that change. Then you are surprised that minicopters don't take player dealt damage. Isn't that what you wanted?

Or is the issue that these minicopter were not claimed and therefore should be taking player damage? If so, a plugin must be assigning ownership to those minicopters. Were they spawned by a plugin, at bandit camp, or along the road? If at bandit camp, the Vehicle Vendor Options plugin has a permission that grants ownership on purchase which you may have enabled.

I meant Minicopters don't take damage at all when they are unclaimed or claimed. When they should take damage once unclaimed, but not when claimed. I actually realised that this was my bad, and might be a bug with TruePVE. They do take damage correctly, but only when using weapons. For some reason if I use any sort of tool they are completely immune. Sorry for the confusion haha

So now you're saying only unclaimed vehicles take player damage as expected, except unclaimed minicopters which only take melee damage in that case, not gun/projectile damage?

Yes exactly! Also Scrap Helicopter for some reason... so everything working as expected except the Minicopter and Scrapheli don't take melee damage, but take projectile damage

Ok so unclaimed minis and scrap helis are immune to melee damage. And other unclaimed vehicles are not. And when you unload the plugin we made in this thread, the issue persists (I assume, since it shouldn't cause this).

Scrap helis extend from the Minicopter class, so likely the plugin blocking melee damage is matching based on the class chain with code like "is Minicopter".

Ahh interesting to know... well I've double checked through all my truepve config to allow all damage to minicopters and scrap heli's but still nothing. I assume something wrong with the cs file itself 

Locked automatically