Hello. This is a economic plugin for my other shop plugin to use. I met a problem that when I run the "[ConsoleCommand("MCmenu2TakePoint")]", it "Put" a result. But next step I call the HookMethod with shop plugin, it Put a another result. And these two results are not same. I don't know why this happend....I think maybe data not updated? If I delete the "[HookMethod("CheckMBPoint")] " and change it to ConsoleCommand, I can get same "Put" result. Sorry for my bad description. Can anyone help me what is wrong with my code? Thanks
StoredData storedData;
class StoredData
{
public Dictionary<string, MBpoint> PlayerStats = new Dictionary<string, MBpoint>();
}
class MBpoint
{
public string LastGetMBDate;
public int MBAmount;
public int FreeMBAmount;
}
void Loaded()
{
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("MCMB");
Interface.Oxide.DataFileSystem.WriteObject("MCMB", storedData);
}
void SaveData()
{
Interface.Oxide.DataFileSystem.WriteObject("MCMB", storedData);
}
[ConsoleCommand("MCmenu2TakePoint")]
private void WithDrawMBPoint(ConsoleSystem.Arg args)
{
var player = args.Connection.player as BasePlayer;
if (player == null)
{
return;
}
if (!storedData.PlayerStats.ContainsKey(player.UserIDString))
{
PrintToChat(player, "you don't have any MBpoint now.");
}
else
{
int price = int.Parse(args.Args[0]);
int MBCount = storedData.PlayerStats[player.UserIDString].MBAmount;
if (MBCount < price)
{
PrintToChat(player, "you don't have enough MBpoint.");
}
else
{
MBCount = MBCount - price;
storedData.PlayerStats[player.UserIDString].MBAmount = MBCount ;
Puts("WithDrawPoint:{0}", MBCount );
SaveData();
}
}
}
[HookMethod("CheckMBPoint")]
public int CheckMB(string playerId)
{
if (string.IsNullOrEmpty(playerId))
{
return 0;
}
if (!storedData.PlayerStats.ContainsKey(playerId))
{
return 0;
}
Puts("checkMBpoint:{0}", storedData.PlayerStats[playerId].MBAmount);
return storedData.PlayerStats[playerId].MBAmount;
}