Hello,
I'm trying to write a small mod that lets players rename their currency in Eco.
I have managed to actually renaming the currency, but, my issue is that when you restart the server, the game seems to be generating new currency for users that don't have one named after them (Username Credits).
So say I was on a server, I would have a currency by the name "Son_Of_Diablo Credits", if I then rename that currency to "Super Awesome Currency" and restart the server, I would then have both "Son_Of_Diablo Credits" and "Super Awesome Currency" attached to my player.
I understand why the game does this, it's to make sure every player has their own currency, specially when new people join a server.
But it's not really what I'm looking for.
My code looks like the following for renaming currency:
[ChatCommand("Renames the users Currency", ChatAuthorizationLevel.User)]
public static void RenameCurrency(User user, string newName)
{
Currency currency = EconomyManager.Currency.Currencies.ToDictionary(c => c.Owner, c => c)[user.Name];
string oldName = currency.CurrencyName;
currency.SetName("(" + newName + ")");
ChatManager.ServerMessageToAllAlreadyLocalized(user.Name + "has renamed their currency from " + oldName + " to " + currency.CurrencyName + "!", true);
}
Does anyone know if there is a way to override the generation of new currency on server start?
Or would I have to have my mod cleaning up the currency if I want to do this?
Thanks in advance!
[automerge]1524014080[/automerge]
I managed to fix the issue by using mampf's mod Asphalt-ModKit using the OnPlayerJoin event.
This is really messy and I really don't like it.
I tried the Initialize method of the IInitializablePlugin too, but it seems like the currency gets added both before and after that event for some reason.
If anyone has any better suggestions please let me know!
Updated Code:
namespace BlankMod
{
using System.Collections.Generic;
using System.Linq;
using Eco.Core.Agents;
using Eco.Core.Serialization;
using Eco.Gameplay.Players;
using Eco.Gameplay.Systems.Chat;
using Eco.Gameplay.Economy;
using Eco.Shared.Math;
using Eco.Shared.Networking;
using Eco.World;
using Eco.Core.Utils;
using Eco.Core.Plugins.Interfaces;
using Eco.Gameplay.Stats;
using Asphalt.Api.Event;
using Asphalt.Api.Event.PlayerEvents;
public class TestCommands : IChatCommandHandler, IInitializablePlugin, IModKitPlugin
{
public TestCommands()
{
EventManager.RegisterListener((object) new SODEvents());
}
[ChatCommand("Dumps a list of all currency", ChatAuthorizationLevel.User)]
public static void DumpCurrency(User user)
{
ChatManager.ServerMessageToAllAlreadyLocalized("--- Dumping Currency ---", true);
ChatManager.ServerMessageToAllAlreadyLocalized("--- Requested by " + user.Name + " ---", true);
ControllerList<Currency> tmpCurrencyDump = EconomyManager.Currency.Currencies;
foreach(Currency c in tmpCurrencyDump)
{
ChatManager.ServerMessageToAllAlreadyLocalized(c.Owner + " - " + c.CurrencyName, true);
}
ChatManager.ServerMessageToAllAlreadyLocalized("--- Dump Done! ---", true);
}
[ChatCommand("Dumps the users currency", ChatAuthorizationLevel.User)]
public static void MyCurrency(User user)
{
Currency currency = EconomyManager.Currency.Currencies.ToDictionary(c => c.Owner, c => c)[user.Name];
ChatManager.ServerMessageToAllAlreadyLocalized(currency.CurrencyName, true);
}
[ChatCommand("Renames the users Currency", ChatAuthorizationLevel.User)]
public static void RenameCurrency(User user, string newName)
{
Currency currency = EconomyManager.Currency.Currencies.ToDictionary(c => c.Owner, c => c)[user.Name];
string oldName = currency.CurrencyName;
currency.SetName("(" + newName + ")");
ChatManager.ServerMessageToAllAlreadyLocalized(user.Name + "has renamed their currency from " + oldName + " to " + currency.CurrencyName + "!", true);
}
[ChatCommand("Delete the specified Currency", ChatAuthorizationLevel.User)]
public static void DeleteCurrency(User user, string name)
{
Currency currency = EconomyManager.Currency.Currencies.ToDictionary(c => c.CurrencyName, c => c)["(" + name + ")"];
EconomyManager.Currency.Currencies.Remove(currency);
}
public string GetStatus()
{
return string.Empty;
}
public void Initialize(TimedTask timer)
{
//ChatManager.ServerMessageToAllAlreadyLocalized("Mod be loaded and stuffs!", false);
//foreach (User user in UserManager.Users)
//{
// ChatManager.ServerMessageToAllAlreadyLocalized(user.Name + " - " + user.Currency.Currencies.Count, false);
// if (user.Currency.Currencies.Count > 1)
// {
// ChatManager.ServerMessageToAllAlreadyLocalized("--- Looking for: (" + user.Name + " Credit)", false);
// foreach (Currency c in user.Currency.Currencies)
// {
// ChatManager.ServerMessageToAllAlreadyLocalized(user.Name + " - " + c.CurrencyName, false);
// if (c.CurrencyName == "(" + user.Name + " Credit)")
// {
// ChatManager.ServerMessageToAllAlreadyLocalized("Found What I Was Looking For, Trying To Remove!", false);
// EconomyManager.Currency.Currencies.Remove(c);
// }
// }
// }
//}
}
}
public class SODEvents
{
[EventHandler]
public void OnPlayerJoin(PlayerLoginEvent evt)
{
//ChatManager.ServerMessageToAllAlreadyLocalized(evt.Player.FriendlyName + " just did a login job! PogChamp", false);
foreach (User user in UserManager.Users)
{
ChatManager.ServerMessageToAllAlreadyLocalized(user.Name + " - " + user.Currency.Currencies.Count, false);
if (user.Currency.Currencies.Count > 1)
{
ChatManager.ServerMessageToAllAlreadyLocalized("--- Looking for: (" + user.Name + " Credit)", false);
foreach (Currency c in user.Currency.Currencies)
{
ChatManager.ServerMessageToAllAlreadyLocalized(user.Name + " - " + c.CurrencyName, false);
if (c.CurrencyName == "(" + user.Name + " Credit)")
{
ChatManager.ServerMessageToAllAlreadyLocalized("Found What I Was Looking For, Trying To Remove!", false);
EconomyManager.Currency.Currencies.Remove(c);
}
}
}
}
}
}
}
Alles anzeigen
I chose to let the commented out lines of code stay so you can see what I have tried before hand