1. How can I get a list of entities of some type which locate inside a circle with some radius?
     
  2. Calytic

    Calytic Community Admin Community Mod

    Code:
    Vector3 position = new Vector3(x, y, z);
    float distance = 20f;
    List<BaseEntity> list = new List<BaseEntity>();
    Vis.Entities<BaseEntity>(position, distance, list);foreach(BaseEntity entity in list) {
          // do something clever
    }
    
     
  3. By the way, what is 20f distance? 20 metres? I know there are own units of mesurement, but are 20 units equal to 20 metres (approximately) ?
     
  4. Calytic

    Calytic Community Admin Community Mod

    I don't know.

    Only hard indication I have is a single unit (1) is 4 feet. Making 20f (f for float) exactly 80 feet. So a little more than a meter per unit, actually in that case.
     
  5. Calytic,

    I am trying to use this to find all ToolCupboards within a 20f radius but I am getting the error: error CS0103: The name `z' does not exist in the current context

    Here is the code:

    Code:
    void GetPlayerTCs(BasePlayer player, BasePlayer target)
            {
                ToolCupboardPrefabId = StringPool.Get(ToolCupboardPrefab);
                if (AuthorizedTC(player))
                   
                {
                    //SendReply(player, $"You are authorized on a nearby ToolCupboard - target is {target}");
                    Vector3 position = new Vector3(x, y, z);
                    float distance = 20f;
                    List<BaseEntity> list = new List<BaseEntity>();
                    Vis.Entities<BaseEntity>(position, distance, list);                foreach (BaseEntity entity in list)
                    {
                        if (entity.prefabID == ToolCupboardPrefabId)
                        {
                            SendReply(player, "There is a ToolCupboard nearby that you are authroized on!");
                            //entity.authorizedPlayers.Add(new ProtoBuf.PlayerNameID() { userid = target.player.userID, username = target.player.displayName });
                        }
                    }
                }
                else if (!AuthorizedTC(player)) SendReply(player, "You are not authorized on a nearby ToolCupboard");        }
    what am I doing wrong? Thanks!!!!
     
  6. How is your program supposed to know what coordinates to find close entities at?
    x, y and z need to be specified. You're passing undeclared variables.
     
  7. I am very new so bare with me! I tried to change it to: Vector3 position =new Vector3() the moment after I posted this because I kind of figured the same thing.. that the system isn't going to assume I want the current position of the argument provider (BasePlayer)

    so long story short, how would I have it pass the BasePlayer coordinates executing the chat command?

    Would it be like....

    Code:
            [ChatCommand("tcauth")]
            void cmdAuthPlayer(BasePlayer player, string cmd, string[] args)
            {
                if (player != null)
                if (args.Length == 0)
                {
                        SendReply(player, "Syntax: /tcauth <PARTIAL_PLAYERNAME>");
                    return;
                }            if (args.Length == 1)
                {
                    var partialPlayerName = args[0];
                    var foundPlayers = FindPlayer(partialPlayerName);
                    if (foundPlayers.Count == 0)
                    {
                        SendReply(player, "No players found");
                        return;
                    }
                    if (foundPlayers.Count > 1)
                    {
                        SendReply(player, "Multiple players found");
                        return;
                    }
                    if (foundPlayers[0] != null)
                    {
                        Vector3 position = new Vector3(player);
                        //SendReply(player, $"Target player is {foundPlayers[0]}");
                        GetPlayerTCs(player, foundPlayers[0], position);
                        return;
                    }
                }
            }
    ......

    Code:
    void GetPlayerTCs(BasePlayer player, BasePlayer target, Vector3 position)
            {
                ToolCupboardPrefabId = StringPool.Get(ToolCupboardPrefab);
                if (AuthorizedTC(player))
                  
                {
                    //SendReply(player, $"You are authorized on a nearby ToolCupboard - target is {target}");
                    float distance = 20f;
                    List<BaseEntity> list = new List<BaseEntity>();
                    Vis.Entities<BaseEntity>(position, distance, list);                foreach (BaseEntity entity in list)
                    {
                        if (entity.prefabID == ToolCupboardPrefabId)
                        {
                            SendReply(player, "There is a ToolCupboard nearby that you are authroized on!");
                            //entity.authorizedPlayers.Add(new ProtoBuf.PlayerNameID() { userid = target.player.userID, username = target.player.displayName });
                        }
                    }
                }
                else if (!AuthorizedTC(player)) SendReply(player, "You are not authorized on a nearby ToolCupboard");        }
    [DOUBLEPOST=1463097736][/DOUBLEPOST]actually is it:

    Vector3 position =new Vector3(player.transform.position)

    ?
     
    Last edited by a moderator: May 13, 2016
  8. No, that will not work.
    Programs are stupid.
    The vector constructor is only defined for a certain set of parameters, it doesn't know how to extract the position from a player.
    I think you should check out a beginners guide on C# to get you started, writing a plugin straight away may be incredibly overwhelming and confusing (mostly because you don't understand why you gotta use certain syntax for certain things).
    You should be able to use player.transform.position to retrieve the position vector, but please learn a bit more about C#, otherwise you'll frequently hit very frustrating and confusing walls while you could be learning a lot more efficiently :)
     
  9. So instead of just posting this..

    Vector3 position = new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z);

    which I figured out "eventually" you decided to lecture me on learning C# : )



    Thanks!
     
  10. You do not need to initialize a new vector.
     
  11. I appreciate your help. I get it, I am not a plugin developer. I'll take my concerns elsewhere.

    Regards,
     
  12. I'm not trying to scare you off, when I started working on Lua plugins for a different game eight years ago I got incredibly frustrated with stuff because I didn't actually understand what I was doing and always had to ask others for help. I wish I had done what I'm recommending to you: Learn the basics beforehand, because that experience scared me off programming for a long time.
    Learn stuff and implement what you learned in your plugin, don't just try to randomly brute force solutions for your plugin because that will be very unrewarding.
     
  13. Indeed. That's the same thing I did. I started off with LUA and I quit nearly every 5 minutes as I got very frustrated. After some time I switched over to C#(Honestly I still don't understand LUA lol) and learned it from there. Of course I looked at nearly every new plugin posted for some help. But I always had people in this community help me like @Wulf, @k1lly0u, etc. So yeah as he said he's not trying to scare you off. More so trying to get you to learn better then how he did.

    You'll never fully understand C# as simply there is just too much information. So don't ever get frustrated when you mess up or you get confused.
     
  14. Code:
    private Vector3 getNewPosition(BasePlayer player)
            {
                PlayerData2 data = Interface.Oxide.DataFileSystem.ReadObject<PlayerData2>($"{player.userID}");
                if (!data.isActiveH) return new Vector3(0,0,0); //if not active, return an empty vector... can't use null.
                float posx = data.posxH;
                float posy = data.posyH;
                float posz = data.poszH;
                Vector3 final = new Vector3(posx, posy, posz);
         
                return final;
            }

    Code:
    var pos = (Vector3)Plugin.CallHook("getNewPosition", player);  
    if (pos is Vector3)
               {
                    float distance = 5f;
                    List<BaseEntity> list = new List<BaseEntity>();
                    Vis.Entities<BaseEntity>(pos, distance, list);
                   int count = 0;                foreach (BaseEntity entity in list)
                    {
                           if (entity.PrefabName.Contains("tool cupboard"))
                        {
                          count++;
                        }
                        
                    }
                   Puts("Count = " + count.ToString());
               }
                    
     
    Last edited by a moderator: May 10, 2018
  15. I am using this code, it works fine thanks. Only thing is when I test this, it detects the cupboard but I get a count = 2 as result. Looks like it double check. How? (previous codes)
     
  16. You can return null if you change the return type to a nullable, the shorthand for which is "Vector3?".