Pvp on cargoship

Is this possible?

not in this plugin. another plugin could do that but im not familiar with which one.

though using a line of code like this should work. can just add it to any plugin for it to work.

private object CanEntityTakeDamage(BasePlayer player, HitInfo info) => player != null && player.HasParent() && player.GetParentEntity() is CargoShip ? true : (object)null;​

So that tiny line. Does not matter what plugin would make it work?
Nothing els like reference to true PvE?

yes, you can do that. though I'd recommend using this since as it would be better for performance

the above code checks for a parent every single time a player took damage regardless of where they are on the map.

the below code checks a list instead. the list is populated by hooks that are called 1 time each. this cuts out the need to check for a parent, and then get that parent if it exists. checking a list is far more performant if that list is small enough, and it always will be.

save as CargoShipPVP.cs

using System.Collections.Generic;

namespace Oxide.Plugins
{
    [Info("Cargo Ship PVP", "nivex", "0.1.0")]
    [Description("Enable PVP while onboard a cargo ship.")]
    public class CargoShipPVP : RustPlugin
    {
        private List<ulong> shipPlayers = new List<ulong>();

        private object CanEntityTakeDamage(BasePlayer player, HitInfo info) => player != null && shipPlayers.Contains(player.userID) ? true : (object)null;

        private void OnEntityEnter(TriggerParent trigger, BasePlayer player)
        {
            if (trigger == null || player == null || player.IsNpc || !player.userID.IsSteamId())
            {
                return;
            }
            if (trigger.gameObject.transform.root.name == "assets/content/vehicles/boats/cargoship/cargoshiptest.prefab")
            {
                shipPlayers.Add(player.userID);
            }
        }

        private void OnEntityLeave(TriggerParent trigger, BasePlayer player)
        {
            if (trigger == null || player == null || player.IsNpc || !player.userID.IsSteamId())
            {
                return;
            }
            if (trigger.gameObject.transform.root.name == "assets/content/vehicles/boats/cargoship/cargoshiptest.prefab")
            {
                shipPlayers.Remove(player.userID);
            }
        }
    }
}​
nivex

yes, you can do that. though I'd recommend using this since as it would be better for performance

the above code checks for a parent every single time a player took damage regardless of where they are on the map.

the below code checks a list instead. the list is populated by hooks that are called 1 time each. this cuts out the need to check for a parent, and then get that parent if it exists. checking a list is far more performant if that list is small enough, and it always will be.

save as CargoShipPVP.cs

using System.Collections.Generic;

namespace Oxide.Plugins
{
    [Info("Cargo Ship PVP", "nivex", "0.1.0")]
    [Description("Enable PVP while onboard a cargo ship.")]
    public class CargoShipPVP : RustPlugin
    {
        private List<ulong> shipPlayers = new List<ulong>();

        private object CanEntityTakeDamage(BasePlayer player, HitInfo info) => player != null && shipPlayers.Contains(player.userID) ? true : (object)null;

        private void OnEntityEnter(TriggerParent trigger, BasePlayer player)
        {
            if (trigger == null || player == null || player.IsNpc || !player.userID.IsSteamId())
            {
                return;
            }
            if (trigger.gameObject.transform.root.name == "assets/content/vehicles/boats/cargoship/cargoshiptest.prefab")
            {
                shipPlayers.Add(player.userID);
            }
        }

        private void OnEntityLeave(TriggerParent trigger, BasePlayer player)
        {
            if (trigger == null || player == null || player.IsNpc || !player.userID.IsSteamId())
            {
                return;
            }
            if (trigger.gameObject.transform.root.name == "assets/content/vehicles/boats/cargoship/cargoshiptest.prefab")
            {
                shipPlayers.Remove(player.userID);
            }
        }
    }
}​

Nice plug-in Nivex thank you I had some players asking about why it wasnt pvp. I there a way to have it display that its a pvp zone kind of like zone manager does?

player.ChatMessage("Entering PVP zone");

player.ChatMessage("Leaving PVP zone");

you can just put those in the code above where it says .Add for Entering and .Remove for Leaving.