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)
Solved Spawning items in chest or on ground? (C#)
Discussion in 'Rust Development' started by Kayzor, Jul 20, 2015.
-
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 -
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; }
Code:dropItem(vector, "pistol_revolver", 1); dropItem(vector, "ammo_pistol", 64); dropItem(vector, "syringe_medical", 2); dropItem(vector, "wolfmeat_cooked", 25);
Many thanks again for the help! -
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.
-
Calytic Community Admin Community Mod
Good to know.
-
-
Calytic Community Admin Community Mod