Hi. I try to read a value inside a datafile of another plugin but don't know how to check it. Plugin has code to create data:
In my new plugin I try to make a IF condition like this:Code:class StoredData { public Dictionary<string, ProfileInfo> ProfileDatabase = new Dictionary<string, ProfileInfo>(); } class ProfileInfo { public string UserId; public string Name; public int Level; public ProfileInfo() { } public ProfileInfo(BasePlayer player) { UserId = player.userID.ToString(); Name = player.displayName; Level = 1; } } StoredData storedData;
That works if data is from the same plugin. How can I use same type of code if it's another plugin? I know aboutCode:ProfileInfo info = storedData.ProfileDatabase[player.userID.ToString()];if (info.Level == 1) return true;
[PluginReference]
Plugin Languages;
I found a lineIs it well used? if plugin name is Profile?Code:object playerData = Profile.Call("GetUserData", player.userID.ToString());
but im confused
[DOUBLEPOST=1441256713,1441164804][/DOUBLEPOST]Only thing I find to read data from external plugin is economy which use lua (yay..). I dont know if I can use the same syntax as that LuaFunction and my plugins are all cs.
How do I convert that lua call to csharp? Anyone knows the answer?Code:private Dictionary<string, LuaFunction> EconomyApi = new Dictionary<string, LuaFunction>(); void OnServerInitialized() { InitializeTable(); if (!Economics) { PrintWarning("Economics plugin not found. " + this.Name + "will not function!"); return; } var apiFuncs = Economics.Call("GetEconomyAPI") as LuaTable; foreach (KeyValuePair<object, object> method in apiFuncs) { var value = method.Value as LuaFunction; if (value != null) EconomyApi.Add(method.Key.ToString(), value); } }
Read data from another plugin?
Discussion in 'Rust Development' started by FireBurst, Sep 3, 2015.
-
Wulf Community Admin
You shouldn't have to call the other plugin at all, just read the datafile the same you would read the datafile for your own plugin. The only difference would be that you'd call the other plugin's file by name when reading it.
Oxide/ConfigFile.cs at master · OxideMod/Oxide · GitHub
Oxide/DynamicConfigFile.cs at master · OxideMod/Oxide · GitHub -
Ok thanks ill have a look. Do you know one plugins that read an external datafile? I could read and learn from it. I kinda just saw the Plugin.Call functions or that Lua Table from economics :S
-
Wulf Community Admin
I don't know any off hand, sorry. The Plugin.Call, Plugin.Exists, and other methods like that are more for calling specific functions in other plugins. It'd be easier just to read the config directly I think. -
reading the configs YES
reading the data NO
because most plugins save data only on server save
so if you read data before a server save you will have out dated data in the data file.
[DOUBLEPOST=1441268552][/DOUBLEPOST]that's why it's better to call the plugin and request for the data -
Call the plugin using call function and using a void that returns a value right?
-
A void does not return anything. It will need to be of the type you want to return. For example string.

