-
Notifications
You must be signed in to change notification settings - Fork 0
/
PunishFF.cs
104 lines (90 loc) · 3.18 KB
/
PunishFF.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("Punish Friendlyfire", "Vliek", "1.0.2", ResourceId = 2813)]
[Description("Punish player by X% of the damage done at friends.")]
class PunishFF : RustPlugin
{
[PluginReference]
private Plugin Friends;
private bool Changed;
private float attackerAmount;
private bool adminPunish;
private string adminPerm;
protected override void LoadDefaultConfig()
{
Puts("Creating a new config file.");
Config.Clear();
LoadVariables();
}
private void LoadVariables()
{
attackerAmount = Convert.ToSingle(GetConfig("Settings", "% of punish damage given (Default 50%)", 0.5));
adminPunish = Convert.ToBoolean(GetConfig("Settings", "Only punish damage on admins", false));
adminPerm = Convert.ToString(GetConfig("Settings", "Admin permission", "PunishFF.admin"));
if (!Changed) return;
SaveConfig();
Changed = false;
}
object GetConfig(string menu, string datavalue, object defaultValue)
{
var data = Config[menu] as Dictionary<string, object>;
if (data == null)
{
data = new Dictionary<string, object>();
Config[menu] = data;
Changed = true;
}
object value;
if (!data.TryGetValue(datavalue, out value))
{
value = defaultValue;
data[datavalue] = value;
Changed = true;
}
return value;
}
private void Init()
{
LoadVariables();
permission.RegisterPermission(adminPerm, this);
}
private object OnAttackInternal(BasePlayer attacker, BasePlayer victim, HitInfo hit)
{
if (attacker == victim)
return null;
float amount = hit.damageTypes.Get(hit.damageTypes.GetMajorityDamageType());
float scale = attackerAmount;
if (!adminPunish)
{
var victimId = victim.userID;
var attackerId = attacker.userID;
var hasFriend = (bool)(Friends?.CallHook("HasFriend", attackerId, victimId) ?? false);
if (hasFriend)
{
attacker.Hurt(amount * scale);
Puts(amount.ToString());
Puts(scale.ToString());
return true;
}
}
else
{
if (!permission.UserHasPermission(victim.UserIDString, adminPerm))
return null;
attacker.Hurt(amount * scale);
Puts(amount.ToString());
Puts(scale.ToString());
return true;
}
return null;
}
void OnPlayerAttack(BasePlayer attacker, HitInfo hitInfo)
{
if (hitInfo?.HitEntity is BasePlayer)
OnAttackInternal(attacker, (BasePlayer)hitInfo.HitEntity, hitInfo);
}
}
}