1. I was hoping someone could point me in the right direction, I am I in the process of making a couple of plugins to help us run PvP events on our server. One of the things I am trying to do is spawn in some items at set locations.

    As far as I can think I have two choices, either spawn the items in a chest or just directly onto the floor?
    However I haven’t been able to find any information about how to target a specific chest or spawn items at a location.

    I am hoping someone could point me to either some documentation or a plugin as reference (or provide a small example)
     
  2. Calytic

    Calytic Community Admin Community Mod

    Please release this when you are finished (and please write it in C#)!

    Containers
    You need some way of getting the StorageContainers.

    Write a command that uses raycast to identify the container you are looking at (lots of plugins do this - Prod comes to mind)

    Add that container to a List<uint>.

    Once you have the containers in the list, you can use item.MoveToContainer(container) to move items into them.

    Saving the StorageContainers is fairly difficult.

    On Ground
    Create a command that records your position - x y z
    Add those positions to a List<Vector3>

    drop items at those positions with item.Drop(position,velocity)
     
    Last edited: Jul 22, 2015
  3. Perfect! Just what I was looking for :)

    I started looking at raycast and spherecast but I shall save that for if I really need to target a chest, for now dropping items on the floor is more than enough and seems so simple!

    I have created the following method for dropping items at a vector location (item shortnames can be found at http://docs.oxidemod.org/rust/#item-list), never know, it might help someone!

    Method:
    Code:
            public bool dropItem(Vector3 vector, string shortName, int amount)
            {
                bool bluePrint = false;
                shortName = shortName.ToLower();            var definition = ItemManager.FindItemDefinition(shortName);
                if (definition != null)
                {
                    Vector3 velocity = new Vector3(0, 0, 0);                Item item = ItemManager.CreateByItemID((int)definition.itemid, amount, bluePrint); // Item stack
                    item.Drop(vector, velocity);                return true;
                }
                return false;
            }
    
    Example:
    Code:
        dropItem(vector, "pistol_revolver", 1);
        dropItem(vector, "ammo_pistol", 64);
        dropItem(vector, "syringe_medical", 2);
        dropItem(vector, "wolfmeat_cooked", 25);
    
    Will release the full plugin once done ^_^

    Many thanks again for the help!
     
  4. Why would persisting containers be any harder than positions? If anything containers are easier you just need to save the entityid... I do that in one of my mods (unreleased) and there was no particular difficulty doing it.
     
  5. Calytic

    Calytic Community Admin Community Mod

    Good to know.
     
  6. Actually I might have assumed things here. I logged on my test server last night and lost associations I did in that mod I was talking about. I haven't looked into it yet, but I have a feeling the entityId's might not persist through server restarts. If that's the case, then it isn't as simple as I thought. I'll do more tests when I get a chance to see what happened.. Worse case I suppose the X/Y/Z pos of the container will persist through restarts so I guess I could use that instead of the entityId and just match containers with my saved positions. Should work until they decide we can move containers :)
     
  7. Calytic

    Calytic Community Admin Community Mod

    That is what I thought..