I tried rewriting my LUA Plugin "Easy Heal" and thats what I've come up with:
Anyways. When trying to compile im getting following error:Code:using System.Collections.Generic; using System.Reflection; using System; using System.Data; using UnityEngine; using Oxide.Core;namespace Oxide.Plugins { [Info("Easy Heal", "LaserHydra", "2.0.0", ResourceId = 984)] [Description("Heal yourself or others")] class EasyHeal : RustPlugin { void Loaded() { string[] foundPlayers; } [ChatCommand("heal")] void cmdHeal(BasePlayer player, string cmd, string[] args) { if (!player.IsAdmin()) { SendChatMessage(player, "HEAL", "You have no permission to use this command!"); return; } if (args.Length != 1) { player.InitializeHealth(100, 100); SendChatMessage(player, "HEAL", "You healed youself!"); return; } if (args.Length == 1) { string[] target; target = GetPlayer(args[0]); if (target.Length == 0) { SendChatMessage(player, "HEAL", "No matching players found!"); } if (target.Length > 1) { SendChatMessage(player, "HEAL", "Multiple players found:"); string multipleUsers = ""; foreach (string matchingplayer in target) { multipleUsers = mutlipleUsers + ", " + matchingplayer; } SendChatMessage(player, "HEAL", multipleUsers); } if (target.Length == 1) { BasePlayer targetPlayer = BasePlayer.Find(target[0]); targetPlayer.InitializeHealth(100,100); SendChatMessage(targetPlayer, "HEAL", "You got healed by <color=orange>" + player.displayName + "</color>"); SendChatMessage(player, "HEAL", "You have healed <color=orange>" + targetPlayer.displayName + "</color>"); } } } //---------------------------> Player finding <---------------------------// void GetPlayer(string searchedPlayer) { string searchedLower = searchedPlayer.ToLower(); foreach (BasePlayer player in BasePlayer.activePlayerList) { string display = player.displayName; string displayLower = display.ToLower(); if (displayLower.Contains(searchedLower)) { int length = foundPlayers.Length + 1; foundPlayers[length] = display; } } if (searchedPlayer == "" || searchedPlayer == null) { return; } return foundPlayers; } //----------------------------> Chat Sending <----------------------------// void BroadcastChat(string prefix, string msg) { PrintToChat("<color=orange>" + prefix + "</color>: " + msg); } void SendChatMessage(BasePlayer player, string prefix, string msg) { SendReply(player, "<color=orange>" + prefix + "</color>: " + msg); } //---------------------------------------------------------------------------// } }
Code:[Oxide] 8:08 PM [Error] EasyHeal.cs(86,13): error CS0127: `Oxide.Plugins.EasyHeal.GetPlayer(string)': A return keyword must not be followed by any expression when method returns void
Solved Help at Debugging in a C# plugin
Discussion in 'Rust Development' started by LaserHydra, Jun 3, 2015.
-
You can't return an expression in a void method, instead use the type it should return.
Code:BasePlayer GetPlayer(string searchedPlayer)
-
Code:string GetPlayer(string searchedPlayer)
-
Google is your friend. Also please follow the tutorials that were linked for you. You wouldn't be asking these questions if you did.
-
umm, I fixed that and some others now. but now I ran into an error which I wasn't able to fix yet.
error:
Code:[Oxide] 12:54 PM [Error] EasyHeal plugin failed to compile! [Oxide] 12:54 PM [Error] EasyHeal.cs(84,20): error CS0029: Cannot implicitly convert type `System.Collections.Generic.List' to `string[]'
Code:using System.Collections.Generic; using System.Reflection; using System; using System.Data; using UnityEngine; using Oxide.Core;namespace Oxide.Plugins { [Info("Easy Heal", "LaserHydra", "2.0.0", ResourceId = 984)] [Description("Heal yourself or others")] class EasyHeal : RustPlugin { [ChatCommand("heal")] void cmdHeal(BasePlayer player, string cmd, string[] args) { if (!player.IsAdmin()) { SendChatMessage(player, "HEAL", "You have no permission to use this command!"); return; } if (args.Length != 1) { player.InitializeHealth(100, 100); SendChatMessage(player, "HEAL", "You healed youself!"); return; } if (args.Length == 1) { string[] target; target = GetPlayer(args[0]); if (target.Length == 0) { SendChatMessage(player, "HEAL", "No matching players found!"); } if (target.Length > 1) { SendChatMessage(player, "HEAL", "Multiple players found:"); string multipleUsers = ""; foreach (string matchingplayer in target) { multipleUsers = multipleUsers + ", " + matchingplayer; } SendChatMessage(player, "HEAL", multipleUsers); } if (target.Length == 1) { BasePlayer targetPlayer = BasePlayer.Find(target[0]); targetPlayer.InitializeHealth(100, 100); SendChatMessage(targetPlayer, "HEAL", "You got healed by <color=orange>" + player.displayName + "</color>"); SendChatMessage(player, "HEAL", "You have healed <color=orange>" + targetPlayer.displayName + "</color>"); } } } //---------------------------> Player finding <---------------------------// string[] GetPlayer(string searchedPlayer) { List<string> foundPlayers = new List<string>(); string searchedLower = searchedPlayer.ToLower(); foreach (BasePlayer player in BasePlayer.activePlayerList) { string display = player.displayName; string displayLower = display.ToLower(); if (!displayLower.Contains(searchedLower)) { Puts(displayLower + " != " + searchedLower); continue; } if (displayLower.Contains(searchedLower)) { Puts(displayLower + " == " + searchedLower); foundPlayers.Add(display); } } foundPlayers.ToArray(); return foundPlayers; } //----------------------------> Chat Sending <----------------------------// void BroadcastChat(string prefix, string msg) { PrintToChat("<color=orange>" + prefix + "</color>: " + msg); } void SendChatMessage(BasePlayer player, string prefix, string msg) { SendReply(player, "<color=orange>" + prefix + "</color>: " + msg); } //---------------------------------------------------------------------------// } }
-
You might want to consider reading up on some more tutorials LaserHydra, on http://csharp.net-tutorials.com/ you can find a nice introduction to C#, it's mainly focused on starting out with a console application which isn't that much of interest for you but it handles most of the basics.
-
Ill take a look at what you sent me
[DOUBLEPOST=1433416159][/DOUBLEPOST]- Failure found