aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tutorials/tut000_setup.md12
-rw-r--r--tutorials/tut010_first_addon.md8
-rw-r--r--tutorials/tut020_nrequire.md6
-rw-r--r--tutorials/tut021_detouring.md8
-rw-r--r--tutorials/tut030_inventories.md22
-rw-r--r--tutorials/tut031_metatables.md4
-rw-r--r--tutorials/tut041_not_enough_items.md7
-rw-r--r--tutorials/tut042_too_many_items.md2
-rw-r--r--tutorials/tut050_entities.md25
9 files changed, 47 insertions, 47 deletions
diff --git a/tutorials/tut000_setup.md b/tutorials/tut000_setup.md
index 7fbe479..77e2700 100644
--- a/tutorials/tut000_setup.md
+++ b/tutorials/tut000_setup.md
@@ -4,14 +4,14 @@
This tutorial covers how to set up Artery so you can begin developing.
-First, you'll need to download the Artery gamemode base. This can be done for updates with [git](https://git-scm.com)(reccomended) or just downloaded as a zip and extracted
+First, you'll need to download the Artery gamemode base. This can be done for updates with [git](https://git-scm.com)(recommended) or just downloaded as a zip and extracted
## Git setup
1. Download [git](https://git-scm.com)
2. Follow the setup instructions
3. Open command prompt and type in `git --version`, verify that version information is printed.
-4. Use the `cd` command to go into your Garry's Mod directory. This is usuallly `C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod` (i.e. the command would be `cd "C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod"`). You can alternatively go to this location in your file browser, then click the file path at the top, and copy+paste it into your command prompt.
+4. Use the `cd` command to go into your Garry's Mod directory. This is usually `C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod` (i.e. the command would be `cd "C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod"`). You can alternatively go to this location in your file browser, then click the file path at the top, and copy+paste it into your command prompt.
5. Use `cd` again to go into your `gamemodes` directory (i.e `cd gamemodes`)
6. Clone the repository `git clone http://cogarr.net/source/cgit.cgi/artery`
7. Go back one level, then into your addons directory and clone the artery_editor addon (`cd ../addons` then `git clone http://cogarr.net/source/cgit.cgi/artery_editor`)
@@ -19,17 +19,17 @@ First, you'll need to download the Artery gamemode base. This can be done for up
9. Another one `git clone https://github.com/CapsAdmin/pac3.git`
10. Download and install [mysqloo](https://gmod.facepunch.com/f/gmodaddon/jjdq/gmsv-mysqloo-v9-Rewritten-MySQL-Module-prepared-statements-transactions/1/)
11. Finally, be sure clients are subscribed to PAC3 on the steam workshop
-12. Boot up gmod, select the artery addon, and load into gm_flatgrass to make sure it works! You can skip the next section, and go on to the next tutorial.
+12. Boot up Garrysmod, select the artery addon, and load into gm_flatgrass to make sure it works! You can skip the next section, and go on to the next tutorial.
## Non-git setup
You'll be doing almost the same thing, only downloading zips instead of using the `git clone` command
1. Go to [cogarr.net/source/cgit.cgi/artery](cogarr.net/source/cgit.cgi/artery) and click the latest version of the zip
-2. Find your garrysmod folder, it'll useually be in `C:/Program Files (x86)/Steam/steamapps/common/GarrysMod/garrysmod`
+2. Find your Garrysmod folder, it'll usually be in `C:/Program Files (x86)/Steam/steamapps/common/GarrysMod/garrysmod`
3. Extract the folder into `garrysmod/gamemodes/` and rename the folder to `artery` so that `garrysmod/gamemodes/artery/README.md` is a valid file.
-3. Downlaod the latest versions of [cogarr.net/source/cgit.cgi/artery_editor](cogarr.net/source/cgit.cgi/artery_editor) and [cogarr.net/source/cgit.cgi/zones](cogarr.net/source/cgit.cgi/zones), and extract them both into the `garrysmod/addons` folder so that `garrysmod/addons/artery_editor/README.txt` and `garrysmod/addons/zones/README.md` are both valid files.
-4. Launch garry's mod (Re-launch if you had it up before) and select the "artery" gamemode, start a server ***with 2 players*** and open console to look for errors.
+3. Download the latest versions of [cogarr.net/source/cgit.cgi/artery_editor](cogarr.net/source/cgit.cgi/artery_editor) and [cogarr.net/source/cgit.cgi/zones](cogarr.net/source/cgit.cgi/zones), and extract them both into the `garrysmod/addons` folder so that `garrysmod/addons/artery_editor/README.txt` and `garrysmod/addons/zones/README.md` are both valid files.
+4. Launch Garry's mod (Re-launch if you had it up before) and select the "artery" gamemode, start a server ***with 2 players*** and open console to look for errors.
Next tutorial: @{tut010_first_addon.md}
diff --git a/tutorials/tut010_first_addon.md b/tutorials/tut010_first_addon.md
index 2fddb28..9c5a3dd 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/my_addon/data/pac3/my_pac.txt` it will appear in the pac editor as a pac you can load!
+You may have seen on the Garrysmod 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 has 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' `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
@@ -18,7 +18,7 @@ Now another `garrysmod/addons/artery_rougelite/data/artery/`
And another `garrysmod/addons/artery_rougelite/data/artery/global/`
-With the folder structure set up, we're ready to actually write some lua.
+With the folder structure set up, we're ready to actually write some Lua.
Create a file `garrysmod/addons/artery_routelite/data/artery/global/helloworld.txt`
@@ -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 in your console(~)!
+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 2881236..ce42df7 100644
--- a/tutorials/tut020_nrequire.md
+++ b/tutorials/tut020_nrequire.md
@@ -73,7 +73,7 @@ The solution is simply to write more of the file path
You don't actually need to save whatever nrequire() returns. If you know the file `sv_invfuncs` adds a method to the player metatable, `player:HasItem(itemname)` which you want to use, you can just call nrequire() without saving the return table.
-garrysmod/addons/artery_routelite/data/artery/global/somefile.lua
+garrysmod/addons/artery_rougelite/data/artery/global/somefile.lua
nrequire("sv_invfuncs.lua")
@@ -90,7 +90,7 @@ Much like the main files of artery, the files under `garrysmod/addons/artery_rou
## Using artery modules
-Let's do an example. On the left, you will see a lot of modules provided by artery. One of these, under "shared" domain is `log.lua`. Open it in a new tab.
+Let's do an example. On the left, you will see a lot of modules provided by artery. One of these, under the "shared" domain is `log.lua`. Open it in a new tab.
You will see several methods provided by `log.lua`, to use them, you will first use nrequire() to get access to the functions, then call whatever you like.
@@ -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 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.
+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. are 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 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 baf6b08..b6c31e3 100644
--- a/tutorials/tut021_detouring.md
+++ b/tutorials/tut021_detouring.md
@@ -1,7 +1,7 @@
# Tut 0x021
## Detouring
-Detouring is a method commonly used in lua, even outside of gmod development. The idea is to redirect a function through your function first, then call the function you're redirecting at the end (or maybe the beginning, or anywhere really). Let's see an example:
+Detouring is a method commonly used in Lua, even outside of Garry's Mod development. The idea is to redirect a function through your function first, then call the function you're redirecting at the end (or maybe the beginning, or anywhere really). Let's see an example:
garrysmod/lua/autorun/detourprint.lua
@@ -12,7 +12,7 @@ garrysmod/lua/autorun/detourprint.lua
oldprint(unpack(args))
end
-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.
+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 doesn't actually show what failed or why. Let's modify it to show a stack trace.
garrysmod/addons/artery\_rougelite/trace\_errors.lua
@@ -26,8 +26,10 @@ garrysmod/addons/artery\_rougelite/trace\_errors.lua
end
-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).
+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).
***Note*** : When detouring, mind the order that you do your logic and the logic that was there before. Does it make sense to do your function first? Maybe it makes more sense to do the usual logic, then come back to your function to do more stuff.
+***Note 2***: Be sure you pass ALL the arguments from the original function through your function. Even if you don't need them, someone else might! If the target function takes a variable number of arguments (It has `...` in the function signature), you must also have `...` in your function signature to capture all arguments.
+
Next tutorial: @{tut030_inventories.md}
diff --git a/tutorials/tut030_inventories.md b/tutorials/tut030_inventories.md
index 41fb293..1ac45a0 100644
--- a/tutorials/tut030_inventories.md
+++ b/tutorials/tut030_inventories.md
@@ -6,23 +6,34 @@ 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" (all the way at the bottom!), 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. invtbl contains a list of methods every inventory has, and itemtbl contains a list of methods every item has.
## A simple inventory
You can see all the fields needed for an inventory, so let's get started. Recall that
function tbl:func_name(one)
+ print(self.Name)
...
end
is the same as
function tbl.func_name(self,one)
+ print(self.Name)
...
end
-lua will automatically create the variable "self" in the first example
+Note the period `tbl.func_name` versus the colon `tbl:func_name`.
+Lua will automatically create the variable "self" in the first example
+
+and that the function calls:
+
+ sometable:dothing("blah")
+
+is the same as
+
+ sometable.dothing(sometable,"blah")
garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
@@ -73,7 +84,7 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
self.weight = self.weight + item.weight
end
- --This one is a bit complicated
+ --This one is a bit complicated, check if we have an item.
--ptr can be either a string, or a function that takes 1 argument,
-- and returns true when given an object we should return.
--this function returns a POSITION that can be given back to get, remove, ect.
@@ -124,8 +135,9 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
--Re-creates this inventory from the data created by Serialize()
function inv:DeSerialize(data)
- local self_copy = table.Copy(self)
local json = util.JSONToTable(data)
+ self.items = {}
+ self.weight = 0
for k,v in pairs(json) do
local item_name = v[1]
local item_data = v[2]
@@ -135,7 +147,7 @@ garrysmod/addons/artery_rougelite/data/artery/global/rougeinv.lua
for k,v in pair(self_copy.items) do
self_copy.weight = self_copy.weight + v.weight
end
- return self_copy
+ return self
end
--Don't forget to register it with the gamemode!
diff --git a/tutorials/tut031_metatables.md b/tutorials/tut031_metatables.md
index a397cc9..62eea66 100644
--- a/tutorials/tut031_metatables.md
+++ b/tutorials/tut031_metatables.md
@@ -2,7 +2,9 @@
## Metatables
-In the last tutorial we saw how to make a simple inventory, but we used a function from Gmod's library that was a bit silly. When we made a copy of our inventory, we used table.Copy() to return a copy seperate to the version in the registry. There's nothing wrong with this, but if you have a lot of fields, and default tables in your inventory, this can get quite costly. There's a simple alternative, lua metatables.
+***TODO:*** Consider scraping this tutorial, it no longer is correct or relevant to inventories (Maybe move it under the item's tutorials?)
+
+In the last tutorial we saw how to make a simple inventory, but we used a function from Gmod's library that was a bit silly. When we made a copy of our inventory, we used table.Copy() to return a copy separate to the version in the registry. There's nothing wrong with this, but if you have a lot of fields, and default tables in your inventory, this can get quite costly. There's a simple alternative, Lua Metatables.
[Programming in Lua](https://www.lua.org/pil/13.html) does a much better job at explaining metatables than I ever could, so take a look at how they use it. We're not going to use all the features they discuss, just 1: the \_\_index method, to replace the DeSerialize() function from @{tut030_inventories.md}.
diff --git a/tutorials/tut041_not_enough_items.md b/tutorials/tut041_not_enough_items.md
index 7b8a65f..650f6f6 100644
--- a/tutorials/tut041_not_enough_items.md
+++ b/tutorials/tut041_not_enough_items.md
@@ -4,14 +4,12 @@
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.Name = "Corpse base"
base.weight = 10
@@ -27,10 +25,9 @@ garrysmod/addons/artery\_rougelite/data/artery/global/npc\_corpses.lua
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"
+ 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!
-
diff --git a/tutorials/tut042_too_many_items.md b/tutorials/tut042_too_many_items.md
index 48ba0cf..489dd77 100644
--- a/tutorials/tut042_too_many_items.md
+++ b/tutorials/tut042_too_many_items.md
@@ -41,3 +41,5 @@ garrysmod/addons/artery\_rougelite/data/artery/global/item\_attributes.txt
end
end
end
+
+Ta-da! It's a little harder to see this in effect, since you need to view an item's .attribute value.
diff --git a/tutorials/tut050_entities.md b/tutorials/tut050_entities.md
index f223228..d4d4200 100644
--- a/tutorials/tut050_entities.md
+++ b/tutorials/tut050_entities.md
@@ -2,7 +2,7 @@
## 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 ![img](http://wiki.garrysmod.com/favicon.ico)[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.
+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 ![img](http://wiki.garrysmod.com/favicon.ico)[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 placing 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:
@@ -26,7 +26,7 @@ garrysmod/addons/artery\_rougelite/data/global/entity\_fountain.txt
print("Mmm... Refreshing!")
end
- scripted_ents.Register(ENT, "artery_fountain")
+ scripted_ents.Register(ENT, "artery_my_fountain")
### Alter
@@ -54,9 +54,9 @@ garrysmod/addons/artery\_rogelite/data/global/entity\_alter.txt
end
end
- scripted_ents.Register(ENT, "artery_fountain")
+ scripted_ents.Register(ENT, "artery_my_alter")
-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.
+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. This allows the server to update the client's information, in case the client needs to show something different on screen depending on an item's attributes.
### Chest
@@ -70,19 +70,4 @@ This one is pretty easy, it's really only here to show you how to extend the ent
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")
+ scripted_ents.Register(ENT, "artery_my_chest")