New Xp Functions

Discussion in 'Rust Development' started by Caffeine, Jul 8, 2016.

  1. Wulf

    Wulf Community Admin

    That would be a float, not an int. ;)
     
  2. Oh i thought he wanted a float haha.
     
  3. Mhh, because I'm Trying this code but I have an error
    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
    If someone can help ?

    Thank to k1lly0u for her code
     

    Attached Files:

  4. if (user = null) needs to be ==
     
  5. 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;
                    }
                }
            }
        }
    }
     
  6. You can use TryParse C# testing to see if a string is an integer?
     
  7. Ok, let me 2 min to try the code
    (Thk for the help)
    [DOUBLEPOST=1468007284][/DOUBLEPOST]I have this output:
    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
    Edit:
    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
  8. SendReply(player, "your message"); also remember you can use colors in your message like <color=#AFE1F5>testing</color>
     
  9. Wulf

    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.
     
  10. Ok, now I have an other problem :(
    Code:
    (22:16:15) | [Oxide] 22:16 [Error] SetLevel.cs(46,44): error CS0103: The name `amount' does not exist in the current context
    I tryed to write "var amount = args[2];"
    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:

  11. Yeah but is not the probelm actually
     
  12. 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
    }
     
  13. 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
     
  14. 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.
     
  15. 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
    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");
                    }
    Always the same problem with this variable "amount"
     
  16. 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;
     
  17. 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 plugin failed to compile!
    (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]
     
  18. Keep the line int amount; above thetryparse, this defines the variable before using it
     
  19. 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'
    Code:
    if (currentlevel<=80) {crafter.xp.Add(Definitions.Cheat, 15);}
    Edit: I found the problem the function "Convert.ToBoolean" need to be rename to "System.Convert.ToBoolean"
     
    Last edited by a moderator: Jul 9, 2016