aboutsummaryrefslogtreecommitdiff
path: root/tutorials/tut041_not_enough_items.md
blob: 7b8a65fd1e5b0baf38fafc868ebb867eea69bf75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Tut 0x041

## Not enough items

It frequently happens that you want many items with only slight variations. In this tutorial we'll see how to create a item drop for every monster. We'll find all the npc's that the game knows about, and create an item (a corpse) for each one.

First, we need to find all the npc's the game knows about, then create an item for each one.

garrysmod/addons/artery\_rougelite/data/artery/global/npc\_corpses.lua

	local reg = nrequire("core/inventory/item.lua")
	local base = {}

	base.Name = "Meat base"

	base.weight = 10

	function base:Serialize()
		return ""
	end

	function base:DeSerialize()
		return table.Copy(self)
	end
	
	local allnpcs = list.Get("NPC")
	for k,v in pairs(allnpcs) do
		if k.Name then
			local item = table.Copy(base) --Make a copy of the above "base" table
			item.Name = k.Name .. " Meat" --Give it a name of "<something> Meat"
			reg.RegisterItem(item) --Add it to the game
		end
	end

That's it! Restart the gamemode, and use `artery_printitems` to see the items in console!