Activating a plugin's function from another plugin
Discussion in 'Rust Discussion' started by w4ssup, Aug 21, 2015.
-
Wulf Community Admin
http://oxidemod.org/threads/call-a-...nal-lua-plugin-in-a-c-plugin.8170/#post-85019
It is pretty much the same for all, but if you'd like more examples, all of my API plugins provide C# examples. -
-
Wulf Community Admin
-
-
Wulf Community Admin
-
-
Wulf Community Admin
-
Code:
MotdGUI.call((cmdMotdShow(BasePlayer player, string cmd, string[] args));
[DOUBLEPOST=1440120714][/DOUBLEPOST]edit again: fix the error, but now I'm getting this error
Code:error CS1061: Type `Oxide.Core.Plugins.Plugin' does not contain a definition for `call' and no extension method `call' of type `Oxide.Core.Plugins.Plugin' could be found. Are you missing an assembly reference?
Last edited by a moderator: Aug 21, 2015 -
Wulf Community Admin
-
Code:
error CS1525: Unexpected symbol `)'
Code:MotdGUI.CallHook((cmdMotdShow(BasePlayer player, string cmd, string[] args)));
Code:MotdGUI.CallHook(cmdMotdShow(BasePlayer player, string cmd, string[] args));
Code:MotdGUI.CallHook(cmdMotdShow);
Code:The name `cmdMotdShow' does not exist in the current context
-
Wulf Community Admin
-
Code:
MotdGUI.CallHook("AppearGUI");
-
Wulf Community Admin
Code:MotdGUI.CallHook("cmdMotdShow", player)
-
Code://Microsoft NameSpaces using System; using System.Collections.Generic;//using UnityEngine; //Oxide NameSpaces using Oxide.Core; using Oxide.Core.Plugins; using Oxide.Core.Libraries; //using Rust;//External NameSpaces using Newtonsoft.Json; private void HappyHours(object sender , object PairObj) { HappyHour myPlugin = (HappyHour)sender; KeyValuePair<string, object> pair = (KeyValuePair<string, object>)PairObj; long CurrentTime = MainTime.GetUnixTimestamp(); Dictionary<string, object> Event = (Dictionary<string, object>)pair.Value; if (CurrentTime < (Convert.ToInt64(Event["NextEvent"].ToString()) + Convert.ToInt64(myPlugin.Config["Time"].ToString()))) { foreach (BasePlayer Player in BasePlayer.activePlayerList) { if (myPlugin.Users.ContainsKey(Player.userID.ToString()) == false) { myPlugin.myPrintToChat(Player, Event["Message"].ToString()); Dictionary<string, object> Items = (Dictionary<string, object>)Event["Items"]; foreach (KeyValuePair<string, object> zItem in (Dictionary<string, object>)Items) { Dictionary<string, object> ItemVars = (Dictionary<string, object>)zItem.Value; Item newItem = ItemManager.CreateByName(ItemVars["ID"].ToString(), Convert.ToInt32(ItemVars["Amount"].ToString())); ItemContainer Cont = null; switch (ItemVars["Amount"].ToString()) { case "Belt": Cont = Player.inventory.containerBelt; break; case "Wear": Cont = Player.inventory.containerWear; break; default: Cont = Player.inventory.containerMain; break; } Player.inventory.GiveItem(newItem, Cont); } myPlugin.Users.Add(Player.userID.ToString(), CurrentTime.ToString()); //*****************************MotdGUI.CallHook("cmdMotdShow", player); } } myPlugin.mySaveData(); Oxide.Core.Libraries.Timer.TimerInstance newTimer = MainTimer.Once(1, () => HappyHours(sender, PairObj), (Plugin)sender); Timers.Add(newTimer); }
Code:using UnityEngine; using Rust; using Oxide.Core.Plugins;namespace Oxide.Plugins { [Info("Motd GUI", "PaiN", 0.1, ResourceId = 0)] [Description("Simple Motd on the screen.")] public class MotdGUI : RustPlugin { System.Collections.Generic.List<ulong> guioff = new System.Collections.Generic.List<ulong>(); void Loaded() { LoadDefaultConfig(); foreach(BasePlayer player in BasePlayer.activePlayerList) { string text = Config["Motd", "Message"].ToString(); string title = Config["Motd", "Title"].ToString(); CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", json.Replace("{text}", text).Replace("{title}", title)); } } protected override void LoadDefaultConfig() { if(Config["Motd", "Message"] == null) Config["Motd", "Message"] = "<color=yellow>Today</color> is a beautiful day!"; if(Config["Motd", "Message"].ToString() != "<color=yellow>Today</color> is a beautiful day!") return; if(Config["Motd", "Title"] == null) Config["Motd", "Title"] = "<color=red>Motd</color>"; if(Config["Motd", "Title"].ToString() != "<color=red>Motd</color>") return; SaveConfig(); } #region JSON string json = @"[ { ""name"": ""Motd"", ""parent"": ""Overlay"", ""components"": [ { ""type"":""UnityEngine.UI.Image"", ""color"":""0.1 0.1 0.1 0"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.3 0.90"", ""anchormax"": ""0.7 0.995"" } ] }, { ""parent"": ""Motd"", ""components"": [ { ""type"":""UnityEngine.UI.Text"", ""text"":""{title}"", ""fontSize"":20, ""align"": ""MiddleCenter"", }, { ""type"":""RectTransform"", ""anchormin"": ""0 0.7"", ""anchormax"": ""1 1"" } ] }, { ""parent"": ""Motd"", ""components"": [ { ""type"":""UnityEngine.UI.Text"", ""text"":""{text}"", ""fontSize"":15, ""align"": ""MiddleCenter"", }, { ""type"":""RectTransform"", ""anchormin"": ""0 0.1"", ""anchormax"": ""1 1.2"" } ] } ] "; #endregion [ChatCommand("motd")] void cmdMotdShow(BasePlayer player, string cmd, string[] args) { if(guioff.Contains(player.userID)) { string text = Config["Motd", "Message"].ToString(); string title = Config["Motd", "Title"].ToString(); CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", json.Replace("{text}", text).Replace("{title}", title)); guioff.Remove(player.userID); } else { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", "Motd"); guioff.Add(player.userID); } } void AppearGUI() { foreach (BasePlayer player in BasePlayer.activePlayerList) { string text = Config["Motd", "Message"].ToString(); string title = Config["Motd", "Title"].ToString(); CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", json.Replace("{text}", text).Replace("{title}", title)); guioff.Remove(player.userID); } } void DisGUI() { foreach (BasePlayer current in BasePlayer.activePlayerList) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = current.net.connection }, null, "DestroyUI", "Motd"); guioff.Add(player.userID); } } [HookMethod("OnPlayerInit")] void OnPlayerInit(BasePlayer player) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", "Motd"); guioff.Add(player.userID); } void Unloaded(BasePlayer player) { foreach (BasePlayer current in BasePlayer.activePlayerList) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = current.net.connection }, null, "DestroyUI", "Motd"); } } void OnPlayerDisconnected(BasePlayer player) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", "Motd"); guioff.Add(player.userID); } } }
Attached Files:
Last edited by a moderator: Aug 21, 2015 -
-
If you want examples lots of my plugin use that.
Évent Manager, Arena Deathmatch, HumanNPC, Jail, etc