blob: 1e1e83786b92b165fb72d166d3038e592d7c9440 (
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
|
# Tut 0x050
## Entities
Usually in addons, you have a dedicated folder for entities, however, that's not the only way to create entities. The canonical way to create entities in artery is to use the [scripted\_ents.Register](http://wiki.garrysmod.com/page/scripted_ents/Register) function. This allows you to register entities after the gamemode has loaded. If your entities don't derive from artery entities, you can still use the usual entity system by placeing a init.lua, cl\_init.lua, and shared.lua in garrysmod/addons/artery\_rougelite/lua/entities.
Let's make some entities that are commonly found in rougelikes. We'll make:
* Fountain - When you go up to and press E on it, you can drink from it.
* Alter - When you go up to and press E on it, it will remove the "cursed" status that we implemented in @{tut042_too_many_items.md}.
* Chest - When you go up to it and press E, it will display an inventory you can put items into. We'll use this later on.
### Fountain
This one is easy enough. Just make an entity that spawns with a model, and accepts a "Use" input.
garrysmod/addons/artery\_rougelite/data/global/entity\_fountain.txt
local ENT = scripted_ents.Get("prop_dynamic")
function ENT:Initalize()
self:SetModel("models/props_c17/fountain_01.mdl")
end
function ENT:Use()
print("Mmm... Refreshing!")
end
scripted_ents.Register(ENT, "artery_fountain")
|