Jump to content

Item distribution


PZ-NOOB

Recommended Posts

Hello my fellow Noobs and Gamers, I have been trying to create a Mod, however I have come across a problem. Item distribution, I have been looking at other peoples code, writing my own code and even trying to get a spawn button to work. But what ever I do I can not get any items to spawn. I have been doing a lot of trial and error but I have decided to ask for help, if your willing to help me I need pretty much everything to do with item distribution and or item spawning explained to me, maybe an example as well xD, don't worry you can laugh at my lack of knowledge.

 

all help will be much appreciated. 

Link to comment
Share on other sites

ModDistribution.lua or whatever you decide to call it should be located in your mod's media\lua\server\Items directory

require 'Items/SuburbsDistributions'------------------------ Trash Items ----------------------table.insert(SuburbsDistributions["all"]["bin"].items, "littering.DogfoodEmpty");table.insert(SuburbsDistributions["all"]["bin"].items, 3);

This piece of code is from my own mod.

 

require 'Items/SuburbsDistributions' - It needs to start with this as this is the path to the original distribution file where we will insert our own items.

 

table.insert(SuburbsDistributions["all"]["bin"].items, "littering.DogfoodEmpty"); 

 

This line will insert an item to the table of items that can spawn in trash bins across the map.

 

"all" is usually the name of the room or type of building like "kitchen" "motel" "hardwarestore" etc.

 

"bin" can be replaced with "shelves" "counter" "fridge" depening on what type of container you want your item to spawn in.

 

littering.DogFoodEmpty - modulename.Itemname from your item script.

 

table.insert(SuburbsDistributions["all"]["bin"].items, 3);

 

The 3 will be the rarity of the item, anything below 1 like 0.1 -> 0.9 will be very rare to rare anything above 1 will be more and more common.

 

To get information about available rooms and containers within them look at the original SuburbsDistributions.lua located in Project Zomboid\media\lua\server\Items

 

    conveniencestore =    {        fridge =        {            rolls = 4,            items = {                "Base.Steak", 3,                "Base.Burger", 3,                "Base.MeatPatty", 3,                "Base.Chicken", 3,                "Base.Ham", 3,                "farming.Bacon", 3,                "Base.Pie", 3,                "Base.Cheese", 4,                "Base.PorkChop", 3,                "Base.MuttonChop", 3,                "Base.Hotdog", 3,                "Base.Corndog", 3,                "farming.MayonnaiseFull", 3,                "farming.RemouladeFull", 3,            }        },

This is a piece of code from original SuburbsDistributions.lua

conveniencestore - Name of the building\room type

fridge - Name of the container

So if we wanted something to spawn in fridges of convenience stores it would look like this.

 

require 'Items/SuburbsDistributions'------------------------ Trash Items ----------------------table.insert(SuburbsDistributions["conveniencestore"]["fridge"].items, "examplemodule.ExampleItem");table.insert(SuburbsDistributions["conveniencestore"]["fridge"].items, 1);

It will spawn ExampleItem from examplemodule script in fridges in convenience stores around the map and it won't be too rare or common.

Link to comment
Share on other sites

How do you want to spawn the items? To spawn then in a players inventory, the format is like this:

Local inv = getSpecificPlayer(player):getInventory();

inv:AddItem("MODULE.ITEM_NAME");

Changing MODULE.ITEM_NAME to the actual item's name. (e.g. Base.Fork to spawn a fork)

Edit: Looks like Svarog beat me to it with much better documentation. :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...