Economics?.CallHook("Deposit", player.userID, (double)item.amount);
player.Command($"chat.say", "/balance");before the update 06.07 everything worked well.
The balance is displayed, but replenishment does not occur.
Economics?.CallHook("Deposit", player.userID, (double)item.amount);
player.Command($"chat.say", "/balance");before the update 06.07 everything worked well.
The balance is displayed, but replenishment does not occur.
Change in Economics.cs all in #region API Methods for
#region API Methods
private double Balance(object playerId)
{
ulong userId;
switch (playerId)
{
case ulong id:
userId = id;
break;
case string id:
if (!ulong.TryParse(id, out userId))
{
LogWarning("Balance method called with invalid player ID string: " + id);
return 0.0;
}
break;
case BasePlayer.EncryptedValue<ulong> id:
userId = id.Get();
break;
case BasePlayer player:
userId = player.userID.Get();
break;
case IPlayer player:
if (!ulong.TryParse(player.Id, out userId))
{
LogWarning("Balance method called with invalid player ID string: " + player.Id);
return 0.0;
}
break;
default:
LogWarning("Balance method called with unsupported player ID type: " + playerId.GetType());
return 0.0;
}
return storedData.Balances.TryGetValue(userId.ToString(), out double playerData)
? playerData
: config.StartingBalance;
}
private bool Deposit(object playerId, double amount)
{
ulong userId;
switch (playerId)
{
case ulong id:
userId = id;
break;
case string id:
if (!ulong.TryParse(id, out userId))
{
LogWarning("Deposit method called with invalid player ID string: " + id);
return false;
}
break;
case BasePlayer.EncryptedValue<ulong> id:
userId = id.Get();
break;
case BasePlayer player:
userId = player.userID.Get();
break;
case IPlayer player:
if (!ulong.TryParse(player.Id, out userId))
{
LogWarning("Deposit method called with invalid player ID string: " + player.Id);
return false;
}
break;
default:
LogWarning("Deposit method called with unsupported player ID type: " + playerId.GetType());
return false;
}
if (amount <= 0) return false;
if (SetBalance(userId.ToString(), amount + Balance(userId.ToString())))
{
Interface.Call("OnEconomicsDeposit", userId.ToString(), amount);
if (config.LogTransactions)
{
LogToFile("transactions",
$"[{DateTime.Now}] {GetLang("LogDeposit", null, amount, userId.ToString())}", this);
}
return true;
}
return false;
}
private bool SetBalance(object playerId, double amount)
{
ulong userId;
switch (playerId)
{
case ulong id:
userId = id;
break;
case string id:
if (!ulong.TryParse(id, out userId))
{
LogWarning("SetBalance method called with invalid player ID string: " + id);
return false;
}
break;
case BasePlayer.EncryptedValue<ulong> id:
userId = id.Get();
break;
case BasePlayer player:
userId = player.userID.Get();
break;
case IPlayer player:
if (!ulong.TryParse(player.Id, out userId))
{
LogWarning("SetBalance method called with invalid player ID string: " + player.Id);
return false;
}
break;
default:
LogWarning("SetBalance method called with unsupported player ID type: " + playerId.GetType());
return false;
}
if (amount >= 0 || config.AllowNegativeBalance)
{
amount = Math.Round(amount, 2);
if (config.BalanceLimit > 0 && amount > config.BalanceLimit)
{
amount = config.BalanceLimit;
}
else if (config.AllowNegativeBalance && config.NegativeBalanceLimit < 0 &&
amount < config.NegativeBalanceLimit)
{
amount = config.NegativeBalanceLimit;
}
storedData.Balances[userId.ToString()] = amount;
changed = true;
Interface.Call("OnEconomicsBalanceUpdated", userId.ToString(), amount);
Interface.CallDeprecatedHook("OnBalanceChanged", "OnEconomicsBalanceUpdated",
new System.DateTime(2022, 7, 1), userId.ToString(), amount);
if (config.LogTransactions)
{
LogToFile("transactions",
$"[{DateTime.Now}] {GetLang("LogSetBalance", null, amount, userId.ToString())}", this);
}
return true;
}
return false;
}
private bool Withdraw(object playerId, double amount)
{
ulong userId;
if (!TryParsePlayerId(playerId, out userId))
{
return false;
}
if (amount >= 0 || config.AllowNegativeBalance)
{
double balance = Balance(userId);
if ((balance >= amount ||
(config.AllowNegativeBalance && balance + amount > config.NegativeBalanceLimit)) &&
SetBalance(userId.ToString(), balance - amount))
{
Interface.Call("OnEconomicsWithdrawl", userId.ToString(), amount);
if (config.LogTransactions)
{
LogToFile("transactions",
$"[{DateTime.Now}] {GetLang("LogWithdrawl", null, amount, userId.ToString())}", this);
}
return true;
}
}
return false;
}
private bool TryParsePlayerId(object playerId, out ulong userId)
{
userId = 0;
switch (playerId)
{
case ulong id:
userId = id;
break;
case string id:
if (!ulong.TryParse(id, out userId))
{
LogWarning("Method called with invalid player ID string: " + id);
return false;
}
break;
case BasePlayer.EncryptedValue<ulong> id:
userId = id.Get();
break;
case BasePlayer player:
userId = player.userID.Get();
break;
case IPlayer player:
if (!ulong.TryParse(player.Id, out userId))
{
LogWarning("Method called with invalid player ID string: " + player.Id);
return false;
}
break;
default:
LogWarning("Method called with unsupported player ID type: " + playerId.GetType());
return false;
}
return true;
}
#endregion API Methods
All will work
Dmitriy4991
Change in Economics.cs all in #region API Methods for
#region API Methods private double Balance(object playerId) { ulong userId; switch (playerId) { case ulong id: userId = id; break; case string id: if (!ulong.TryParse(id, out userId)) { LogWarning("Balance method called with invalid player ID string: " + id); return 0.0; } break; case BasePlayer.EncryptedValue<ulong> id: userId = id.Get(); break; case BasePlayer player: userId = player.userID.Get(); break; case IPlayer player: if (!ulong.TryParse(player.Id, out userId)) { LogWarning("Balance method called with invalid player ID string: " + player.Id); return 0.0; } break; default: LogWarning("Balance method called with unsupported player ID type: " + playerId.GetType()); return 0.0; } return storedData.Balances.TryGetValue(userId.ToString(), out double playerData) ? playerData : config.StartingBalance; } private bool Deposit(object playerId, double amount) { ulong userId; switch (playerId) { case ulong id: userId = id; break; case string id: if (!ulong.TryParse(id, out userId)) { LogWarning("Deposit method called with invalid player ID string: " + id); return false; } break; case BasePlayer.EncryptedValue<ulong> id: userId = id.Get(); break; case BasePlayer player: userId = player.userID.Get(); break; case IPlayer player: if (!ulong.TryParse(player.Id, out userId)) { LogWarning("Deposit method called with invalid player ID string: " + player.Id); return false; } break; default: LogWarning("Deposit method called with unsupported player ID type: " + playerId.GetType()); return false; } if (amount <= 0) return false; if (SetBalance(userId.ToString(), amount + Balance(userId.ToString()))) { Interface.Call("OnEconomicsDeposit", userId.ToString(), amount); if (config.LogTransactions) { LogToFile("transactions", $"[{DateTime.Now}] {GetLang("LogDeposit", null, amount, userId.ToString())}", this); } return true; } return false; } private bool SetBalance(object playerId, double amount) { ulong userId; switch (playerId) { case ulong id: userId = id; break; case string id: if (!ulong.TryParse(id, out userId)) { LogWarning("SetBalance method called with invalid player ID string: " + id); return false; } break; case BasePlayer.EncryptedValue<ulong> id: userId = id.Get(); break; case BasePlayer player: userId = player.userID.Get(); break; case IPlayer player: if (!ulong.TryParse(player.Id, out userId)) { LogWarning("SetBalance method called with invalid player ID string: " + player.Id); return false; } break; default: LogWarning("SetBalance method called with unsupported player ID type: " + playerId.GetType()); return false; } if (amount >= 0 || config.AllowNegativeBalance) { amount = Math.Round(amount, 2); if (config.BalanceLimit > 0 && amount > config.BalanceLimit) { amount = config.BalanceLimit; } else if (config.AllowNegativeBalance && config.NegativeBalanceLimit < 0 && amount < config.NegativeBalanceLimit) { amount = config.NegativeBalanceLimit; } storedData.Balances[userId.ToString()] = amount; changed = true; Interface.Call("OnEconomicsBalanceUpdated", userId.ToString(), amount); Interface.CallDeprecatedHook("OnBalanceChanged", "OnEconomicsBalanceUpdated", new System.DateTime(2022, 7, 1), userId.ToString(), amount); if (config.LogTransactions) { LogToFile("transactions", $"[{DateTime.Now}] {GetLang("LogSetBalance", null, amount, userId.ToString())}", this); } return true; } return false; } private bool Withdraw(object playerId, double amount) { ulong userId; if (!TryParsePlayerId(playerId, out userId)) { return false; } if (amount >= 0 || config.AllowNegativeBalance) { double balance = Balance(userId); if ((balance >= amount || (config.AllowNegativeBalance && balance + amount > config.NegativeBalanceLimit)) && SetBalance(userId.ToString(), balance - amount)) { Interface.Call("OnEconomicsWithdrawl", userId.ToString(), amount); if (config.LogTransactions) { LogToFile("transactions", $"[{DateTime.Now}] {GetLang("LogWithdrawl", null, amount, userId.ToString())}", this); } return true; } } return false; } private bool TryParsePlayerId(object playerId, out ulong userId) { userId = 0; switch (playerId) { case ulong id: userId = id; break; case string id: if (!ulong.TryParse(id, out userId)) { LogWarning("Method called with invalid player ID string: " + id); return false; } break; case BasePlayer.EncryptedValue<ulong> id: userId = id.Get(); break; case BasePlayer player: userId = player.userID.Get(); break; case IPlayer player: if (!ulong.TryParse(player.Id, out userId)) { LogWarning("Method called with invalid player ID string: " + player.Id); return false; } break; default: LogWarning("Method called with unsupported player ID type: " + playerId.GetType()); return false; } return true; } #endregion API Methods All will work
didn't work for me