New Xp Functions
Discussion in 'Rust Development' started by Caffeine, Jul 8, 2016.
-
Wulf Community Admin
-
Oh i thought he wanted a float haha.
-
Mhh, because I'm Trying this code but I have an error
If someone can help ?Code:(21:02:47) | [Oxide] 21:03 [Error] SetLevel plugin failed to compile! (21:02:47) | [Oxide] 21:03 [Error] SetLevel.cs(31,13): error CS9010: Primary constructor body is not allowed
Thank to k1lly0u for her codeAttached Files:
-
-
if (user = null) needs to be ==
-
There was a few errors on that code.
I did not test it but try this:
Code:using System.Collections.Generic; using Oxide.Core; using Oxide.Core.Configuration; using Rust.Xp; namespace Oxide.Plugins { [Info("SetLevel", "MrErne", "0.1", ResourceId = 0)] class SetLevel : RustPlugin { private void ResetPlayerLevel(BasePlayer player, float amount) { if (player == null) return; player.xp.Reset(); player.xp.Add(Definitions.Cheat, amount); } [ChatCommand("level")] private void level(BasePlayer player, string command, string[] args) { if (!player.IsAdmin()) return; if (args == null || args.Length == 0) { SendMSG(player, "/level <playername> <amount>"); } if (args.Length > 1) { var user = FindPlayer(player, args[1]); if (user == null) { SendMSG(player, "User not found"); return; } int amount = args[2]; if (amount > 300 || amount < 0) { SendMSG(player, "You cannot set level more than 300 and less than 0"); return; } else { ResetPlayerLevel(target, amount); SendMSG(player, "Level are set to"); SendMSG(user, "An admin fix your level to"); return; } } } } } -
You can use TryParse C# testing to see if a string is an integer?
-
Ok, let me 2 min to try the code
(Thk for the help)
[DOUBLEPOST=1468007284][/DOUBLEPOST]I have this output:
Edit:Code:(21:47:13) | [Oxide] 21:47 [Error] SetLevel plugin failed to compile! (21:47:13) | [Oxide] 21:47 [Error] SetLevel.cs(48,21): error CS0103: The name `SendMSG' does not exist in the current context
My bad SendMSG is not the fonction to send a Message into the gamme sry.
What's is the name of the oxide fonction ?Last edited by a moderator: Jul 8, 2016 -
SendReply(player, "your message"); also remember you can use colors in your message like <color=#AFE1F5>testing</color>
-
Wulf Community Admin
PrintToChat(player, message) is what most use. I don't think Oxide has a SendReply natively, Rust has an arg.ReplyWith and player.ChatMessage natively. -
Ok, now I have an other problem
I tryed to write "var amount = args[2];"Code:(22:16:15) | [Oxide] 22:16 [Error] SetLevel.cs(46,44): error CS0103: The name `amount' does not exist in the current context
But doesn't work
Code:(22:16:57) | [Oxide] 22:17 [Error] SetLevel.cs(37,21): error CS0019: Operator `>' cannot be applied to operands of type `string' and `int'
Attached Files:
-
-
SendReply still works https://dl.dropboxusercontent.com/u/50354233/20160708163327_1.jpg
-
Yeah but is not the probelm actually
-
MrErne you need to convert to an int I believe
Code:int amount; if (Int32.TryParse(args[2], out amount)) { if (amount > 300 || amount < 0) { etc.... } } else { //wasn't a valid int } -
Doesn't work
(23:11:23) | [Oxide] 23:11 [Error] SetLevel.cs(38,9): error CS0103: The name `Int32' does not exist in the current context -
Try adding
using System;
to the top, if that doesn't fix it i'll test out the code and see if I can get it working. -
Code:
(23:32:42) | [Oxide] 23:33 [Error] SetLevel plugin failed to compile! (23:32:42) | [Oxide] 23:33 [Error] SetLevel.cs(38,17): error CS0841: A local variable `amount' cannot be used before it is declared
Always the same problem with this variable "amount"Code:amount = args[2]; int amount; if (Int32.TryParse(args[2], out amount)) { ResetPlayerLevel(user, amount); PrintToChat(player, "Level are set to"); PrintToChat(user, "An admin fix your level to"); return; }else{ PrintToChat(player, "You cannot set level more than 300 and less than 0"); } -
remove the line amount = args[2]; as the amount variable is already filled with the new tryparse line I added. Also you tried using it before it was declared a line below it at int amount;
-
(00:18:38) | [Oxide] 00:18 [Error] SetLevel plugin failed to compile!Code:
if (Int32.TryParse(args[2], out amount)) { ResetPlayerLevel(user, amount); PrintToChat(player, "Level are set to"); PrintToChat(user, "An admin fix your level to"); return; }else{ PrintToChat(player, "You cannot set level more than 300 and less than 0"); }
(00:18:38) | [Oxide] 00:18 [Error] SetLevel.cs(42,29): error CS0103: The name `amount' does not exist in the current context
The same output, I just ween i type /level [pseudo] [amount] set the level [amount] -
Keep the line int amount; above thetryparse, this defines the variable before using it
-
New error about Xp and the update
Code:(08:31:08) | [Oxide] 08:31 [Error] MagicCraft.cs(167,55): error CS0104: `Convert' is an ambiguous reference between `System.Convert' and `Rust.Xp.Convert'
Edit: I found the problem the function "Convert.ToBoolean" need to be rename to "System.Convert.ToBoolean"Code:if (currentlevel<=80) {crafter.xp.Add(Definitions.Cheat, 15);}Last edited by a moderator: Jul 9, 2016
