1. I am trying to find a item on the map based on his UID, I tried to use some tricks with GameEntity, but it failed. I just started with Oxide and I need a little of help as it is quite basic question.

    Here is my code

    Code:
    namespace Oxide.Plugins
    {
        [Info("EpicPlugin", "Unknown", 0.1)]
        [Description("Makes epic stuff happen")]    class EpicPlugin : RustPlugin
        {
            // The rest of the code and magic
            void Init()
            {
                Puts("Hi hello!");
            }        void OnPlayerChat(ConsoleSystem.Arg arg)
            {
                Puts("ITS ME, SERVER!");
                var player = BasePlayer.Find("Płomyk");
                var item = ItemManager.CreateByItemID(-770311783);  // a wooden box
                Puts(item.uid.ToString());                          // 22701
                player.GiveItem(item);
            }
        }
    }
    So far so good, but later I can't find this wooden box with UID 22701 :(

    I wish I could tell something more, but all my efforts were like blind bullets :s
     
  2. What do you mean you can't find the box? You're creating the box and giving it to the player Piomyk - does this not work?
     
  3. I mean that I can't assign it to variable again, like in the following pseudocode:

    CreateItemByID(...)
    GiveThisItemToPlayer()
    <player puts it on the ground>
    var item_on_the_ground = FindThisItemPlease(UID) // Can't achieve this

    And if you want to ask why I want to assign it again - just in case of server restart or player logout, etc.
     
  4. Well if I remember correctly UIDs are unique per server session and so differ upon server restart.

    Can you show the code where you're trying to find it again? You've only posted giving the box and displaying its UID.
     
  5. Ok I solved my problem, here is a little piece of code that can help somebody in future

    Code:
    var items = WorldItem.Util.FindTargets("box", false); // *box* on the map
    for (int i = 0; i < items.Length; i++)
    {
        Puts("Item name: " + items[i].name);
        Puts("Item instance: " + items[i].gameObject.GetInstanceID());
        Puts("Owner: " + items[i].OwnerID.ToString());
    }
    I could not obtain steam user name but I am not sure if this is a problem, not for me and not for now :)
     
  6. You could create the box like you did to start with and save the net.id to data, then you can find the box using it instead of looping through every 'box' on the server
     
  7. Calytic

    Calytic Community Admin Community Mod

    Perhaps this..
    Code:
    StorageContainer box = (StorageContainer)BaseNetworkable.serverEntities.Find(net.ID);
    StorageContainer box1 = BaseNetworkable.serverEntities.Find(net.ID).GetComponent<StorageContainer>();
     
  8. What do you mean by "to data"? What is the data container that survives server restart etc.? I am thinking about database but afaik Rust uses just files for that kind of stuff which personally annoys me very much as it is a huge limitation sadly

    Interesting approach, I will look into it later as there are many ways to achieve the same result with some differences that need to be analysed more deeply, more likely what is a GetComponent method
     
  9. Calytic

    Calytic Community Admin Community Mod

    AFAIK there is no method that retains entity IDs across restarts. You'll have to use a method like I used to with EntityOwner.

    Code:
    public static string GetEntityID(BaseEntity entity)
    {
        Vector3 position = entity.transform.position;
        return "x" + position.x + "y" + position.y + "z" + position.z;
    }
    
     
  10. I am pretty sure the net.ID is the same through restarts. I use it in quite a few plugins with out any known issues. Seeing your post had me worried for a minute and I had to go test it out :p
    Please correct me if I am wrong
     
  11. Calytic

    Calytic Community Admin Community Mod

    I wouldn't be surprised if they fixed this. Thanks for the info @k1lly0u