1. Code:
       private Vector3 position;
       private float distance;
    void Init()
            {
                position = new Vector3((float) Config.Get("alterX"), (float) Config.Get("alterY"), (float) Config.Get("alterZ"));  //Sets the mecca point
                distance = (float) Config.Get("prayerDistance");  // sets the distance you need to be within to /pray
            
                Puts("[Plugin] Mecca Initialized!");
            }
    [ChatCommand("pray")]
            void PrayCommand(BasePlayer player, string command, string[] args)
            {
                var list = new List<BaseEntity>();
                 Vis.Entities<BaseEntity>(position, distance, list); //Gets every entity with in this parameter
                  foreach (var entity in list)
                  {
                      if(player.name == entity.ToPlayer().name) //Looks for an entity with players name
                      {
                          SendChatMessage(player, (string)Config["Title"], (string)Config["Message"]);
                          player.inventory.GiveItem(ItemManager.CreateByName((string)Config["prize"],1)); //gives c4 for praying configurable
                      }
                  }
      
            }
    
    I'm getting this

    [2/12/2016 7:59:54 PM] [Oxide] 7:59 PM [Error] Failed to initialize plugin 'Mecca v0.0.4' (InvalidCastException: Cannot cast from source type to destination type.)

    I can't figure out where I messed up I really would appreciate some help.


    Code:
       void SendChatMessage(BasePlayer player, string prefix, string msg = null) => SendReply(player, msg == null ? prefix : "<color=#00FF8D>" + prefix + "</color>: " + msg);
    That's the SendChatMessage, That works fine because my /loc command works which is this

    Code:
      [ChatCommand("loc")]
            void LocCommand(BasePlayer player, string command, string[] args)
            {
          
                var x = player.transform.position.x.ToString();
                var y = player.transform.position.y.ToString();
                var z = player.transform.position.z.ToString();
                SendChatMessage(player, (string)Config["Title"], "Your Location is: ( X: " + x + " Y: " + y + " Z: " + z + ")");
            }
    
    If I had to guess the cause I would say it's saying I can't use a float for a vector like such.
    Code:
    position = new Vector3((float) Config.Get("alterX"), (float) Config.Get("alterY"), (float) Config.Get("alterZ"));  //Sets the mecca point

    I fixed the player.ToPlayer() I'm dumb for not noticing that. But thanks for pointing that out but that did not fix my problem.

    My Console printout

    Code:
    [Oxide] 8:38 PM [Debug]   at Oxide.Plugins.Mecca.Init () [0x00000] in <filename
    unknown>:0
      at Oxide.Plugins.Mecca.DirectCallHook (System.String name, System.Object& ret,
    System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (System.Reflection.MethodInfo metho
    d, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[]
    args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.HandleAddedToManager (Oxide.Core.Plugins.Plugin
    Manager manager) [0x00000] in <filename unknown>:0
    
     
    Last edited by a moderator: Feb 13, 2016
  2. Does SendChatMessage take a player and 2 strings? I don't know what the function is but you could try putting both your strings together
    SendChatMessage(player.ToPlayer(), (string)Config["Title"] + (string)Config["Message"]);
     
  3. Wulf

    Wulf Community Admin

    Well, to start with, player is already a player, so you do not need to cast it to a player again.

    It may be a custom one, because it isn't being used from Oxide's library, as you'd need to prefix with rust. for that.
     
  4. Added to first post.
     
    Last edited by a moderator: Feb 13, 2016
  5. This is just a guess but you have player.inventory.GiveItem and the container set to 1?
    Does that work? I usually set the container
    player.inventory.containerBelt
    player.inventory.containerMain
    player.inventory.containerWear

    edit sorry i misread, the 1 is the amount :p
     
  6. So I have 100% identified the cause is that The vector I'm setting up Cant convert object to float how would I go around that @Wulf ?
     
  7. try a parse or Convert.ToSingle(Config.Get("Key"))