-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathZaupUconomyEssentials.cs
171 lines (166 loc) · 6.94 KB
/
ZaupUconomyEssentials.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.Linq;
using Rocket.API;
using Rocket.API.Collections;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned;
using Rocket.Unturned.Player;
using Rocket.Unturned.Plugins;
using SDG.Unturned;
using fr34kyn01535.Uconomy;
namespace Uconomy_Essentials
{
public class Uconomy_Essentials : RocketPlugin<UconomyEConfiguration>
{
public static Uconomy_Essentials Instance;
public Dictionary<string, decimal> PayGroups = new Dictionary<string,decimal>();
protected override void Load() {
Uconomy_Essentials.Instance = this;
List<Group> nlgroup = this.Configuration.Instance.PayGroups.Distinct( new GroupComparer()).ToList();
this.Configuration.Instance.PayGroups = nlgroup;
foreach (Group g in this.Configuration.Instance.PayGroups)
{
try
{
this.PayGroups.Add(g.DisplayName, g.Salary);
}
catch (Exception e)
{
Logger.LogException(e);
//Logger.Log(g.DisplayName + " " + g.Salary.ToString());
//Logger.Log("There was an exception: " + e);
}
}
}
protected override void Unload()
{
Uconomy_Essentials.Instance.PayGroups.Clear();
}
public delegate void PlayerPaidEvent(UnturnedPlayer player, decimal amount);
public event PlayerPaidEvent OnPlayerPaid;
public delegate void PlayerLossEvent(UnturnedPlayer player, decimal amount);
public event PlayerLossEvent OnPlayerLoss;
public delegate void PlayerExchangeEvent(UnturnedPlayer player, decimal currency, uint experience, string type);
public event PlayerExchangeEvent OnPlayerExchange;
public override TranslationList DefaultTranslations
{
get
{
return new TranslationList
{
{
"pay_time_msg",
"You have received {0} {1} in salary for being a {2}."
},
{
"unable_to_pay_group_msg",
"Unable to pay {0} as no {1} group salary set."
},
{
"to_killer_msg",
"You have received {0} {1} for killing {2}."
},
{
"lose_suicide_msg",
"You have had {0} {1} deducted from your account for committing suicide."
},
{
"new_balance_msg",
"Your new balance is {0} {1}."
},
{
"lose_money_on_death_msg",
"You have lost {0} {1} for being killed."
},
{
"apay_msg",
"You have paid {0} {1} {2}."
},
{
"apaid_msg",
"{0} gave you {1} {2}. You now have {3} {4}."
},
{
"experience_exchange_not_available",
"I'm sorry, experience exchange is not available. Ask your admin to enable it."
},
{
"money_exchange_not_available",
"I'm sorry, money exchange is not available. Ask your admin to enable it."
},
{
"exchange_zero_amount_error",
"You have to enter an amount of experience/money to exchange."
},
{
"exchange_insufficient_experience",
"You don't have {0} exprience."
},
{
"exchange_insufficent_money",
"You don't have {0} {1}."
},
{
"apay_usage_msg",
"Usage: /apay <player name or id> <amt>"
},
{
"exchange_usage_msg",
"Usage: /exchange <amount>[ money] (including money will exchange money to xp otherwise defaults xp to money)"
},
{
"not_valid_player_msg",
"{0} is not a valid player name or steam id."
},
{
"not_valid_amount",
"{0} is not a correct amount."
},
{
"zombie_kill_paid_msg",
"You have been paid {0} {1} for killing a zombie. Your balance is now {2} {3}."
},
{
"mega_zombie_kill_paid_msg",
"You have been paid {0} {1} for killing a mega zombie. Your balance is now {2} {3}."
}
};
}
}
public static void HandleEvent(UnturnedPlayer player, decimal amount, string eventtype, uint exp = 0, string type = "experience")
{
if (eventtype == "exchange" && exp <= 0)
{
Logger.Log("OnPlayerExchange could not be fired as no experience was given.");
return;
}
if (amount == 0.0m || player == null) {
Logger.Log(eventtype + " was not fired as player or amount not given.");
return;
}
switch (eventtype)
{
case "paid":
if (Uconomy_Essentials.Instance.OnPlayerPaid != null)
Uconomy_Essentials.Instance.OnPlayerPaid(player, amount);
player.Player.gameObject.SendMessage("UEOnPlayerPaid", new object[] { player, amount });
break;
case "loss":
if (Uconomy_Essentials.Instance.OnPlayerLoss != null)
Uconomy_Essentials.Instance.OnPlayerLoss(player, amount);
player.Player.gameObject.SendMessage("UEOnPlayerLoss", new object[] { player, amount });
break;
case "exchange":
if (Uconomy_Essentials.Instance.OnPlayerExchange != null)
Uconomy_Essentials.Instance.OnPlayerExchange(player, amount, exp, type);
player.Player.gameObject.SendMessage("UEOnPlayerExchange", new object[] { player, amount, exp, type });
break;
default:
Logger.Log("Invalid type supplied to throw paid/loss/experience event.");
break;
}
}
}
}