Hello Oxide! I can't seem to find the solution on google, so I'm here posting - hoping someone can find something in my code. The symptom is that whenever I reload my plugin, it always creates a new datafile rather than loading the data within it. The plugin and its IO behavior works as intended during gameplay.
Loading data through this method, which init() calls with LoadData();
private void LoadData()
{
try
{
Puts("loading datafile..{0}", Name.ToString());
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>(Name);
Puts("Datafile loaded");
}
catch
{
storedData = null;
}
if (storedData == null)
{
Puts("-- no datafile, creating new..");
ClearData();
}
}
StoredData class;
private class StoredData
{
[JsonProperty("Monument Sesssions")]
public List<MSession> m_sessions { get; set; } = new List<MSession>();
public StoredData()
{
}
}
MSession class;
private class MSession
{
[JsonProperty("Player Id")]
public string player_id;
[JsonProperty("Locked by admin?")]
private bool locked_by_admin {get; set;} = false;
[JsonProperty("Team ID")]
private string team_id;
[JsonProperty("Monument")]
public Monument SessionMonument = new Monument();
[JsonProperty("Session started_at")]
private string started_at;
[JsonProperty("Session updated_at")]
private string updated_at;
[JsonProperty("Session ended_at")]
private string ended_at;
[JsonProperty("Session duration(sec)")]
private double duration;
public MSession(string _player_id, Monument _monument, bool is_admin=false)
{
player_id = _player_id;
team_id = GetPlayer(_player_id).currentTeam.ToString();
SessionMonument = _monument;
locked_by_admin = is_admin;
started_at = DateTime.Now.ToString();
updated_at = DateTime.Now.ToString();
duration = 0;
}
}
When my datafile looks like this, oxide loads it as intended (instead of creating a new one);
{
"Monument Sesssions": []
}
When my datafile looks like this, oxide creates a new file (instead of loading it);
{
"Monument Sesssions": [
{
"Player Id": "76561############",
"Team ID": "0",
"Monument": {
"Enabled: Is Monument enabled?": true,
"Lock Looting: When a player enters this monument while locked, do we lock their looting abilities?": true,
"Cancel Cards: When a player enters this monument while locked, do we lock their card swiping abilities?": true,
"Lock Crate: When a player enters this monument while locked, do we lock their hacking on locked crates?": true,
"Broadcasting: Do we want this plugin to broadcast to the server when this monument is locked?": true,
"Monument Display Name": "Large Harbor",
"Monument Prefab Name": "assets/bundled/prefabs/autospawn/monument/harbor/harbor_1.prefab",
"Monument Short Name": "harbor_1",
"Monument Grid Position": "B10",
"Lock Attack: When a player enters a locked monument, do we lock their attacking abilities?": true,
"Lock timer (600 = 10 min)?": 600
},
"Session started_at": "03/04/2023 16:27:48",
"Session updated_at": "03/04/2023 16:27:48",
"Session ended_at": null,
"Session duration(sec)": 0.0,
"Locked by admin?": false
}
]
}