forked from Freenex1911/FeexHitman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeexHitman.cs
111 lines (99 loc) · 4.87 KB
/
FeexHitman.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
105
106
107
108
109
110
111
using fr34kyn01535.Uconomy;
using Rocket.API;
using Rocket.API.Collections;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Events;
using Rocket.Unturned.Player;
using Steamworks;
namespace Freenex.FeexHitman
{
public class FeexHitman : RocketPlugin<FeexHitmanConfiguration>
{
public DatabaseManager FeexHitmanDatabase;
public static FeexHitman Instance;
public override TranslationList DefaultTranslations
{
get
{
return new TranslationList(){
{"hitman_general_chat_created","Bounty placed: {0} ({1} $)"},
{"hitman_general_chat_increased","Bounty increased by {1} $: {0} ({2} $)"},
{"hitman_general_chat_received","{0} killed {1} and received the bounty of {2} $ ({3} %)."},
{"hitman_general_not_found","Player not found."},
{"hitman_general_invalid_parameter","Invalid parameter."},
{"hitman_add_self","You can't place bounty on yourself."},
{"hitman_add_amount","That's not a valid amount."},
{"hitman_add_balance","You do not have enough money to place a bounty."},
{"hitman_add_minimum","The bounty must be at least {0} $."},
{"hitman_payout","The bounty of {0} has been paid to you. ({1} $)."},
{"hitman_check_true","{0} has a bounty of {1} $."},
{"hitman_check_false","{0} has no bounty."},
{"hitman_list_true","{0} player/s on bounty list: {1}"},
{"hitman_list_false","The bounty list is empty."}
};
}
}
protected override void Load()
{
Instance = this;
FeexHitmanDatabase = new DatabaseManager();
U.Events.OnPlayerConnected += Events_OnPlayerConnected;
UnturnedPlayerEvents.OnPlayerDeath += UnturnedPlayerEvents_OnPlayerDeath;
Logger.Log("Freenex's FeexHitman has been loaded!");
}
protected override void Unload()
{
U.Events.OnPlayerConnected -= Events_OnPlayerConnected;
UnturnedPlayerEvents.OnPlayerDeath -= UnturnedPlayerEvents_OnPlayerDeath;
Logger.Log("Freenex's FeexHitman has been unloaded!");
}
private void Events_OnPlayerConnected(UnturnedPlayer player)
{
if (FeexHitman.Instance.FeexHitmanDatabase.CheckExists(player.CSteamID))
{
FeexHitman.Instance.FeexHitmanDatabase.UpdateVictimDisplayName(player.CSteamID, player.CharacterName);
}
}
private void UnturnedPlayerEvents_OnPlayerDeath(UnturnedPlayer player, SDG.Unturned.EDeathCause cause, SDG.Unturned.ELimb limb, CSteamID murderer)
{
UnturnedPlayer UPmurderer = UnturnedPlayer.FromCSteamID(murderer);
try
{
if (player.Id == UPmurderer.Id) { return; }
}
catch { return; }
decimal BountyPercentage = 0;
foreach (Rocket.API.Serialisation.Permission playerPermission in UPmurderer.GetPermissions())
{
if (playerPermission.Name.ToLower().Contains("hitman.receive."))
{
string BountyPermission = playerPermission.Name.ToLower().Replace("hitman.receive.", string.Empty);
decimal BountyPercentagePermission;
bool isPercentageNumeric = decimal.TryParse(BountyPermission, out BountyPercentagePermission);
if (!isPercentageNumeric) { Logger.LogError(BountyPermission + " is not numeric."); return; }
if (BountyPercentagePermission > BountyPercentage)
{
BountyPercentage = BountyPercentagePermission;
}
}
}
if (BountyPercentage != 0)
{
if (FeexHitman.Instance.FeexHitmanDatabase.CheckExists(player.CSteamID))
{
decimal amount = FeexHitman.Instance.FeexHitmanDatabase.GetBounty(player.CSteamID);
amount = System.Math.Round(amount * (BountyPercentage / 100), 2);
Uconomy.Instance.Database.IncreaseBalance(UPmurderer.Id, amount);
FeexHitman.Instance.FeexHitmanDatabase.RemoveVictimAccount(player.CSteamID);
if (FeexHitman.Instance.Translations.Instance.Translate("hitman_general_chat_received") != "hitman_general_chat_received")
{
UnturnedChat.Say(FeexHitman.Instance.Translations.Instance.Translate("hitman_general_chat_received", UPmurderer.CharacterName, player.CharacterName, amount.ToString(), BountyPercentage), UnityEngine.Color.yellow);
}
}
}
}
}
}