Skip to content
Prev Previous commit
Next Next commit
Fix: Credits are Number-Formatted in all eco commands
  • Loading branch information
LordTylus committed Dec 29, 2023
commit d02b80a8c8763566519790d771b7b37a7a63cd21
29 changes: 15 additions & 14 deletions Essentials/Commands/EcoModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Essentials.Commands
{
[Category("econ")]
public class EcoModule : CommandModule {

[Command("give", "Add a specified anount of credits into a users account. Use '*' to affect all players")]
[Permission(MyPromoteLevel.Admin)]
public void EcoGive(string Player, long amount) {
Expand All @@ -32,19 +33,19 @@ public void EcoGive(string Player, long amount) {
return;
}
p.TryGetBalanceInfo(out long balance);
Context.Respond($"new bal will be {balance + amount}");
Context.Respond($"new bal will be {balance + amount:#,##0}");
p.RequestChangeBalance(amount);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been added to your virtual account", 10000, "Blue"), p.SteamUserId);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount:#,##0} credits have been added to your virtual account", 10000, "Blue"), p.SteamUserId);

}
else {
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
MyBankingSystem.ChangeBalance(IdentityID, amount);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been added to your virtual account", 10000, "Blue"), p.SteamId);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount:#,##0} credits have been added to your virtual account", 10000, "Blue"), p.SteamId);
}
}
Context.Respond($"{amount} credits given to account(s)");
Context.Respond($"{amount:#,##0} credits given to account(s)");
}

[Command("take", "Take a specified anount of credits from a users account. Use '*' to affect all players")]
Expand All @@ -58,17 +59,17 @@ public void EcoTake(string Player, long amount) {
}
long changefactor = 0 - amount;
p.RequestChangeBalance(changefactor);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been taken to your virtual account", 10000, "Blue"), p.SteamUserId);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount:#,##0} credits have been taken to your virtual account", 10000, "Blue"), p.SteamUserId);
}
else {
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
long balance = MyBankingSystem.GetBalance(IdentityID);
MyBankingSystem.ChangeBalance(IdentityID, -amount);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount} credits have been taken to your virtual account", 10000, "Blue"), p.SteamId);
ModCommunication.SendMessageTo(new NotificationMessage($"{amount:#,##0} credits have been taken to your virtual account", 10000, "Blue"), p.SteamId);
}
}
Context.Respond($"{amount} credits taken from account(s)");
Context.Respond($"{amount:#,##0} credits taken from account(s)");
}

[Command("set", "Set a users account to a specifed balance. Use '*' to affect all players")]
Expand All @@ -83,18 +84,18 @@ public void EcoSet(string Player, long amount) {
p.TryGetBalanceInfo(out long balance);
long difference = (balance - amount);
p.RequestChangeBalance(-difference);
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount} credits!", 10000, "Blue"), p.SteamUserId);
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount:#,##0} credits!", 10000, "Blue"), p.SteamUserId);
}
else {
foreach (var p in MySession.Static.Players.GetAllPlayers()) {
long IdentityID = MySession.Static.Players.TryGetIdentityId(p.SteamId);
long balance = MyBankingSystem.GetBalance(IdentityID);
long difference = (balance - amount);
MyBankingSystem.ChangeBalance(IdentityID, -difference);
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount} credits!", 10000, "Blue"), p.SteamId);
ModCommunication.SendMessageTo(new NotificationMessage($"Your balance has been set to {amount:#,##0} credits!", 10000, "Blue"), p.SteamId);
}
}
Context.Respond($"Balance(s) set to {amount}");
Context.Respond($"Balance(s) set to {amount:#,##0}");
}

[Command("reset", "Reset the credits in a users account to 10,000. Use '*' to affect all players")]
Expand Down Expand Up @@ -147,7 +148,7 @@ public void EcoTop() {
var sorted = balances.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
foreach (var value in sorted) {
var test = MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key);
ecodata.AppendLine($"Player: {MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key).ToString()} - Balance: {value.Value.ToString()}");
ecodata.AppendLine($"Player: {MySession.Static.Players.TryGetIdentityNameFromSteamId(value.Key)} - Balance: {value.Value:#,##0}");
}

if (Context.Player == null) {
Expand All @@ -166,7 +167,7 @@ public void EcoCheck(string Player) {
return;
}
long balance = MyBankingSystem.GetBalance(p.Identity.IdentityId);
Context.Respond($"{p.DisplayName}'s balance is {balance} credits");
Context.Respond($"{p.DisplayName}'s balance is {balance:#,##0} credits");
}

[Command("pay")]
Expand All @@ -186,8 +187,8 @@ public void EcoPay(string Player, long amount) {
var finalToBalance = MyBankingSystem.GetBalance(p.Identity.IdentityId) + amount;

MyBankingSystem.RequestTransfer_BroadcastToClients(Context.Player.Identity.IdentityId, p.Identity.IdentityId, amount, finalFromBalance, finalToBalance);
ModCommunication.SendMessageTo(new NotificationMessage($"Your have recieved {amount} credits from {Context.Player}!", 10000, "Blue"),p.SteamUserId);
ModCommunication.SendMessageTo(new NotificationMessage($"Your have sent {amount} credits to {p.DisplayName}!", 10000, "Blue"),Context.Player.SteamUserId);
ModCommunication.SendMessageTo(new NotificationMessage($"Your have recieved {amount:#,##0} credits from {Context.Player}!", 10000, "Blue"),p.SteamUserId);
ModCommunication.SendMessageTo(new NotificationMessage($"Your have sent {amount:#,##0} credits to {p.DisplayName}!", 10000, "Blue"),Context.Player.SteamUserId);
}

}
Expand Down