Hi Everyone,
I was wondering if someone could help out in creating a data file, I already looked in the docs as well as other plugins to see if I could find something to suit my needs but I couldn't.
I want to know how I could create a data file looking something like the following and also maybe how to read it:
Thanks in advanceCode:{ "steamid": { "item.shortname": 0, "item.shortname": 0 } "steamid": { "item.shortname": 0, "item.shortname": 0 } }
Creating a data file?
Discussion in 'Rust Development' started by 4lex, Feb 19, 2017.
-
The docs are a bit weird I can agree(for data files at least).
Code:StoredData storedData; class StoredData{ Dictionary<ulong, ItemClass> data = new Dictionary<ulong, ItemClass>(); } class ItemClass{ Dictionary<string, int> items = new Dictionary<string, int>(); }
-
Thanks for all your help, they should update the docs for data files with something like that along with an explanation.
Wait one more thing now how would I read that information from the file, if say I wanted to find the value of rifle.ak in the following datafile below?
Code:{ "7656xxxxxx": { "rifle.ak": 5, "item.shortname": 0 } "steamid": { "item.shortname": 0, "item.shortname": 0 } }
-
storedData.data[player.userID].items["rifle.ak"]; //returns 5
or if your using string userid
storedData.data[player.UserIDString].items["rifle.ak"]; //returns 5 -
How do I add the steamIDs in the ulong?
i have tried doing something like;
Code:[ChatCommand("Test")] void Test(BasePlayer player, string command, string[] args) { ulong userid = player.userID; if (storedData.data.Contains(player.userID)) return; PrintToChat(player, "Saving your data to the file"); storedData.data.Add(userid); Interface.Oxide.DataFileSystem.WriteObject("Datafile", storedData); }
Last edited by a moderator: Feb 19, 2017 -
I get this error error CS1501: No overload for method `Add' takes `1' arguments
-
storedData.data.Add(userid, new ItemClass());
-
Now I get this error;
error CS0122: `Oxide.Plugins.MyPlugin.StoredData.data' is inaccessible due to its protection level -
-
Sorry to keep bugging you but, how would I say add rifle.ak to someone and also how do I check whether the steamid already exist inside the data file
EDIT
I got how to check for the steamID already exist but what about adding the rifle.ak with value
Code:if (storedData.data.ContainsKey(userid)) return;
I got that too for adding
Code:if (!storedData.data.ContainsKey(userid)) storedData.data.Add(userid, new ItemClass()); storedData.data[userid].items.Add("rifle.ak", num);
Last edited by a moderator: Feb 20, 2017