I completely understand what you're saying.Even the smallest check to see if a value or permission is set adds up when it has to be done 1000 times.And there are definitely some plugins that aren't very efficiently written.
I don't mean to badmouth any particular plugins, but I actually have a purchased one running that calls another plugin's interface far too often and then relies entirely on the garbage collector.I've submitted an elaborated bug report and hope the developer takes care of it.
That said, yes I'm learning and wrote my first plugin only for the sole purpose of loot protection for sleepers. I borrowed the isAlly() code from you, so it works with Teams, Clans and Friends. I attache the code here, maybe you can give a comment on it or it will safe some time if you choose to implement it in TruePvE.
By the way at the uMod plugin page of TruePvE is not stated, that it works with Teams, Clans and Friends. Maybe you should correct this. And last but not least: Is it possible to get TruePvE as git repository? Now that I've got a taste for it, I'd like to make these small additions directly in TruePvE. Then I'd have the option to merge them again in the next update if you don't like them in the main branch.
Greetz
using System;
using System.Collections.Generic;
using Oxide.Core.Plugins;
namespace Oxide.Plugins
{
[Info("Player Loot Protection", "ToliburtiX", "1.0.0")]
[Description("Protects players being looted by other players than allies. Works with Teams, Clans and Friends.")]
class PlayerLootProtection : CovalencePlugin
{
[PluginReference]
Plugin Clans, Friends;
// Players (default group) may get loot protection.
private const string permEnable = "playerlootprotection.enable";
// Admins (admin group) may get bypass permission.
private const string permBypass = "playerlootprotection.bypass";
private void Init()
{
permission.RegisterPermission(permEnable, this);
permission.RegisterPermission(permBypass, this);
}
private object isPlayerProtected(BasePlayer looter, ulong entityID)
{
if (!permission.UserHasPermission(looter.userID.ToString(), permBypass))
{
if (looter.userID != entityID && !IsAlly(looter.userID, entityID) && permission.UserHasPermission(entityID.ToString(), permEnable))
{
NextFrame(looter.EndLooting);
return true;
}
}
return null;
}
private object OnLootEntity(BasePlayer looter, BasePlayer sleeper)
{
return isPlayerProtected(looter, sleeper.userID);
}
private object OnLootEntity(BasePlayer looter, LootableCorpse corpse)
{
return isPlayerProtected(looter, corpse.playerSteamID);
}
private object OnLootEntity(BasePlayer looter, DroppedItemContainer container)
{
return isPlayerProtected(looter, container.playerSteamID);
}
private bool IsAlly(ulong vic, ulong atk) => vic switch
{
_ when vic == atk => true,
_ when RelationshipManager.ServerInstance.playerToTeam.TryGetValue(vic, out var team) && team.members.Contains(atk) => true,
_ when Clans != null && Convert.ToBoolean(Clans?.Call("IsClanMember", vic, atk)) => true,
_ when Friends != null && Convert.ToBoolean(Friends?.Call("AreFriends", vic, atk)) => true,
_ => false
};
}
}