aboutsummaryrefslogtreecommitdiff
path: root/tutorials
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-02-28 09:41:23 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2018-02-28 09:41:23 -0500
commit5fd5f2b3d1c77c3b85355c452ffc7e1fe2e12162 (patch)
treeba03a7c2975e2c5c88732cc28be90365e6cd41aa /tutorials
parenta77ee4ce201de757ce4c5958d9e499a65b2cf416 (diff)
downloadartery-5fd5f2b3d1c77c3b85355c452ffc7e1fe2e12162.tar.gz
artery-5fd5f2b3d1c77c3b85355c452ffc7e1fe2e12162.tar.bz2
artery-5fd5f2b3d1c77c3b85355c452ffc7e1fe2e12162.zip
Fixed some types, worked on 0x050
Fixed typos in a bunch of tutorials, did a little more work on 0x050 - Entities
Diffstat (limited to 'tutorials')
-rw-r--r--tutorials/tut010_first_addon.md6
-rw-r--r--tutorials/tut020_nrequire.md4
-rw-r--r--tutorials/tut021_detouring.md4
-rw-r--r--tutorials/tut030_inventories.md8
-rw-r--r--tutorials/tut040_items.md2
-rw-r--r--tutorials/tut042_too_many_items.md10
-rw-r--r--tutorials/tut050_entities.md25
7 files changed, 45 insertions, 14 deletions
diff --git a/tutorials/tut010_first_addon.md b/tutorials/tut010_first_addon.md
index d4f8cb1..2fddb28 100644
--- a/tutorials/tut010_first_addon.md
+++ b/tutorials/tut010_first_addon.md
@@ -4,9 +4,9 @@
A quick primer on addons for Garry's Mod, and Artery.
-You may have seen on the gmod wiki, instructions on running lua code. One way is to place files in your `garrysmod/lua/autorun` directory, and they will be run automatically when you enter single player. This can get messy though, another way to run lua is by making a folder in `garrysmod/addons/<addon_name>/lua/autorun`, and placing your scripts in that (i.e. so that `garrysmod/addons/my_first_addon/lua/autorun/hello.lua` is a valid file). As it turns out, all folders under `garrysmod/addons/<addon_name>` get reflected! This means that if you have a file `garrysmod/addons/data/pac3/my_pac.txt` it will appear in the pac editor as a pac you can load!
+You may have seen on the gmod wiki, instructions on running lua code. One way is to place files in your `garrysmod/lua/autorun` directory, and they will be run automatically when you enter single player. This can get messy though, another way to run lua is by making a folder in `garrysmod/addons/<addon_name>/lua/autorun`, and placing your scripts in that (i.e. so that `garrysmod/addons/my_first_addon/lua/autorun/hello.lua` is a valid file). As it turns out, all folders under `garrysmod/addons/<addon_name>` get reflected! This means that if you have a file `garrysmod/addons/my_addon/data/pac3/my_pac.txt` it will appear in the pac editor as a pac you can load!
-This is the method used by addons for Artery. Since Garry's Mod loads addons's autorun BEFORE gamemodes, Artery uses the `data/artery/global/` folder to run scripts after the gamemode as loaded (and therefore has access to the nrequire() function, more on this later).
+This is the method used by addons for Artery. Since Garry's Mod loads addons's autorun BEFORE gamemodes, Artery uses the `data/artery/global/` folder to run scripts after the gamemode has loaded (and therefore has access to the nrequire() function, more on this later).
## Lets get started
@@ -26,6 +26,6 @@ and copy+paste the following code into it.
print("Hello, world!")
-Now start up garrysmod with the Artery gamemode selected. Head into flatgrass or something. Open your console, you should see "Hello, world!" printed.
+Now start up garrysmod with the Artery gamemode selected. Head into flatgrass or something. Open your console, you should see "Hello, world!" printed in your console(~)!
Next tutorial: @{tut020_nrequire.md}
diff --git a/tutorials/tut020_nrequire.md b/tutorials/tut020_nrequire.md
index 2d0cb6d..2881236 100644
--- a/tutorials/tut020_nrequire.md
+++ b/tutorials/tut020_nrequire.md
@@ -86,7 +86,7 @@ garrysmod/addons/artery_routelite/data/artery/global/somefile.lua
nrequire() is automatically loads all the other modules in artery. It runs them in the client or server domain depending on their file name, much like DarkRP. If the file begins with `sv_` it is run on the server only, if it begins with `cl_` it is sent to the client and run on the client only. Anything else will be run on both the server and the client.
-Much likes the main files of artery, the files under `garrysmod/addons/artery_rougelite/data/artery/global` will follow the same scheme. If you want your data to only be run on only the server or client, just name the file beginning with `sv_` or `cl_`.
+Much like the main files of artery, the files under `garrysmod/addons/artery_rougelite/data/artery/global` will follow the same scheme. If you want your data to only be run on only the server or client, just name the file beginning with `sv_` or `cl_`.
## Using artery modules
@@ -105,7 +105,7 @@ Note that we named the file `logthing.lua`, since the file does not begin with `
## Next steps
-From here the tutorials open up a bit. You can continue on, or read more in depth about the subject. Tutorials named tut030, tut040, ect. are in logical order needed to build an addon for Artery, tutorials named tut031, tut041, ect. would be continuations of tut030 and tut040 respectively.
+From here the tutorials open up a bit. You can continue on, or read more in depth about the subject. Tutorials named tut030, tut040, ect. are in logical order needed to build an addon for Artery, tutorials named tut031, tut041, ect. would be continuations of tut030 and tut040 respectively that go more in depth or expand on the ideas about the content of their parent tutorial. These are not nessessarilly needed to complete the tutorial addon, but are recommended viewing before asking for help from the developer.
Further reading: @{tut021_detouring.md}
Next tutorial: @{tut030_inventories.md}
diff --git a/tutorials/tut021_detouring.md b/tutorials/tut021_detouring.md
index 7e4c980..a03a31d 100644
--- a/tutorials/tut021_detouring.md
+++ b/tutorials/tut021_detouring.md
@@ -14,7 +14,7 @@ garrysmod/lua/autorun/detourprint.lua
The above script __replaces__ the print function, with a new function, which eventually calls the original print function, with modified arguments. The above can be done with modules in Artery as well. For example, `log.lua`'s .error() function currently only prints a message in red, it dosn't actually show what failed or why. Let's modify it to show a stack trace.
-garrysmod/addons/artery_rougelite/trace_errors.lua
+garrysmod/addons/artery\_rougelite/trace\_errors.lua
local log = nrequire("log.lua")
local colors = nrequire("config/colortheme.lua") --Holds colors
@@ -27,3 +27,5 @@ garrysmod/addons/artery_rougelite/trace_errors.lua
For more information on colortheme.lua see @{colortheme.lua}, for more on debug.traceback() see [the gmod wiki](http://wiki.garrysmod.com/page/debug/traceback).
+
+Next tutorial: @{tut030_inventories.md}
diff --git a/tutorials/tut030_inventories.md b/tutorials/tut030_inventories.md
index fbf654d..41fb293 100644
--- a/tutorials/tut030_inventories.md
+++ b/tutorials/tut030_inventories.md
@@ -6,7 +6,7 @@ Many gamemode bases try to build an inventory system into the gamemode, leaving
In this tutorial, we'll build a simple rougelike inventory, where we expect items to have a "weight", and we can carry as many items as we want, as long as we don't exceed our "max weight".
-Inventories and items in Artery are just tables, as per usual in lua. They have a few required fields each. On the left, under "Classes", open invtbl and itemtbl in new tabs.
+Inventories and items in Artery are just tables, as per usual in lua. They have a few required fields each. On the left, under "Classes" (all the way at the bottom!), open invtbl and itemtbl in new tabs.
## A simple inventory
@@ -115,7 +115,8 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
for k,v in pairs(self.items) do
ser[k] = {
v.Name,
- v:Serialize()
+ v:Serialize() --Take advantage of the fact that all items must also have a
+ -- Serialize() method
}
end
return util.TableToJSON(ser)
@@ -142,3 +143,6 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
That was a bit long, but we're done! This is the absolute minimum needed to create an Artery inventory. Now you can go in-game and use the console command `artery_printinventories`, and in that list, you will see your newly made inventory!
+
+Next tutorial: @{tut040_items.md}
+Further reading: @{tut031_metatables.md}
diff --git a/tutorials/tut040_items.md b/tutorials/tut040_items.md
index 954f9cd..1a44884 100644
--- a/tutorials/tut040_items.md
+++ b/tutorials/tut040_items.md
@@ -13,7 +13,7 @@ Items are a lot like inventories, but much simpler. Let's make one!
return ""
end
- --Recall that we said in @{tut030_inventories.md} we said items that work in our inventory will have a .weight field
+ --Recall that we said in @{tut030_inventories.md} that items that work in our inventory will have a .weight field
item.weight = 20
function item:DeSerialize()
diff --git a/tutorials/tut042_too_many_items.md b/tutorials/tut042_too_many_items.md
index bcea957..9d95b00 100644
--- a/tutorials/tut042_too_many_items.md
+++ b/tutorials/tut042_too_many_items.md
@@ -2,15 +2,15 @@
## Too many items
-In the last tutorial we saw how to create lots and lots of items. Sometimes, you think to yourself "that's way too many", and when you do, you simplify. Rougelike games have a tendency to have attributes associated with items. Commonly, "blessed", normal, and "cursed". In this tutorial, we'll be using the technique discussed in @{tut021_detouring.md} to give every item one of these stats by overrideing @{item.lua.RegisterItem} the Serialize() and DeSerialize() methods to give every item a little extra data.
+In the last tutorial we saw how to create lots and lots of items. Sometimes, you think to yourself "that's way too many", and when you do, you simplify. Rougelike games have a tendency to have attributes associated with items. Commonly, "blessed", "normal", and "cursed". In this tutorial, we'll be using the technique discussed in @{tut021_detouring.md} to give every item one of these stats by overrideing @{item.lua.RegisterItem} the Serialize() and DeSerialize() methods to give every item a little extra data.
-garrysmod/addons/artery_rougelite/data/artery/global/item_attributes.txt
+garrysmod/addons/artery\_rougelite/data/artery/global/item\_attributes.txt
local itm = nrequire("item.lua")
local log = nrequire("log.lua")
- local oldregister = item.RegisterItem
+ local oldregister = itm.RegisterItem
function itm.RegisterItem(itemtbl)
local oldserialize = itemtbl.Serialize
local olddeserialize = itemtbl.DeSerialize
@@ -34,8 +34,8 @@ garrysmod/addons/artery_rougelite/data/artery/global/item_attributes.txt
self.attribute = 1
elseif firstchar == "c" then
self.attribute = -1
- elseif firstchar == "n" then
- self.attribute = 0
+ elseif firstchar == "n" then -- Notice above, the item dosn't nessessarilly need a .attribute field.
+ self.attribute = nil
else
log.error("Deserialized with unknown first character: " .. firstchar)
end
diff --git a/tutorials/tut050_entities.md b/tutorials/tut050_entities.md
index 1e1e837..e443cae 100644
--- a/tutorials/tut050_entities.md
+++ b/tutorials/tut050_entities.md
@@ -27,3 +27,28 @@ garrysmod/addons/artery\_rougelite/data/global/entity\_fountain.txt
end
scripted_ents.Register(ENT, "artery_fountain")
+
+garrysmod/addons/artery\_rogelite/data/global/entity\_alter.txt
+
+ local ENT = scripted_ents.Get("prop_dynamic")
+
+ 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
+
+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.