Hello,
I'm trying to understand what I did wrong in the example of data files that uMod provide (https://umod.org/documentation/api/data-files).
From what I understand, if I'm already in the data file, it only reply a message else it add me to the file. But it's not working, it add me to the file everytime I run the command...
Can you help me?
I'm trying to understand what I did wrong in the example of data files that uMod provide (https://umod.org/documentation/api/data-files).
From what I understand, if I'm already in the data file, it only reply a message else it add me to the file. But it's not working, it add me to the file everytime I run the command...
Can you help me?
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("Plugin Name", "Author", "1.0.0")]
[Description("Description of the plugin.")]
class PluginName : CovalencePlugin
{
private StoredData storedData;
private class StoredData
{
public HashSet<PlayerInfo> Players = new HashSet<PlayerInfo>();
public StoredData()
{
}
}
private void Init()
{
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("MyDataFile");
}
void Loaded()
{
Puts("Loaded works!");
}
private class PlayerInfo
{
public string Id;
public string Name;
public PlayerInfo()
{
}
public PlayerInfo(IPlayer player)
{
Id = player.Id;
Name = player.Name;
}
}
[Command("test")]
private void TestCommand(IPlayer player, string command, string[] args)
{
PlayerInfo info = new PlayerInfo(player);
if (storedData.Players.Contains(info))
{
player.Reply("Your data has already been added to the file");
}
else
{
storedData.Players.Add(info);
player.Reply("Saving your data to the file...");
Interface.Oxide.DataFileSystem.WriteObject("MyDataFile", storedData);
}
}
}
}