diff options
Diffstat (limited to 'tutorials/tut050_entities.md')
| -rw-r--r-- | tutorials/tut050_entities.md | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tutorials/tut050_entities.md b/tutorials/tut050_entities.md index e443cae..f223228 100644 --- a/tutorials/tut050_entities.md +++ b/tutorials/tut050_entities.md @@ -28,6 +28,9 @@ garrysmod/addons/artery\_rougelite/data/global/entity\_fountain.txt scripted_ents.Register(ENT, "artery_fountain") +### Alter + +Use mostly the same approach. You can skip this entity if you never went through @{tut042_too_many_items.md} garrysmod/addons/artery\_rogelite/data/global/entity\_alter.txt local ENT = scripted_ents.Get("prop_dynamic") @@ -50,5 +53,36 @@ garrysmod/addons/artery\_rogelite/data/global/entity\_alter.txt ply:GiveItem(item) end end + + scripted_ents.Register(ENT, "artery_fountain") It may have been tempting here to just set the item's .attribute in our iscursed() function, since it will be the first place we detect a cursed item. **HOWEVER!** There are a lot of places in Artery that this kind of thing can BREAK other addons. Generally speaking, try not to modify items while they're in an inventory. Remove them, modify them, then add them back. + +### Chest + +This one is pretty easy, it's really only here to show you how to extend the entities that are already in Artery. + + local ENT = scripted_ents.Get("prop_dynamic") + + DEFINE_BASECLASS("art_chest") -- this defines a local variable called BaseClass + + function ENT:Initalize() + self:SetModel("models/props_junk/wood_crate002a.mdl") + end + + function ENT:Use(ply) + --Get all the items the player has that are cursed + local iscursed = function(item) + if item.attribute == -1 then -- Item is cursed + return true + end + end + local to_uncurse_pos = ply:HasItem(iscursed) + while(to_uncurse_pos) do --Will be nil if we don't have any cursed items + local item = ply:RemoveItem(to_uncurse_pos) + item.attribute = nil + ply:GiveItem(item) + end + end + + scripted_ents.Register(ENT, "artery_fountain") |
