aboutsummaryrefslogtreecommitdiff
path: root/tutorials/tut041_not_enough_items.md
blob: 650f6f6760379a2e131fce9b20b0c72b4723cef8 (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
# 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.

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

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

	base.Name = "Corpse 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 .. " Corpse" --Give it a name of "<something> Corpse"
			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!