Hi and welcome to the second mod-lesson for a Family of Grave Diggers!
Well, the first post was just an overview so we could consider this one to be the first real mod post, but enough talking, lets dive in and get to work! Now, now, not too fast, lets start with something easy just to check things out.
A potion that adds 1 point of attack permanently, the Strength Potion (Graphics Credits Ail)!
So what do we need:
- A 34×34 icon for the item (right click, save link as…)
- A text editor (for example Notepad++)
- Around 20 minutes
- Open your game folder, the copied one (see post 1 for instructions where you have copied it), open Mod/gfx/item and copy the icon in the two folders /mapsize and /slotsize.
- Move up two levels (or back if you prefer) to the /Mod folder and open /Script/Item/potion
- Create a new file named “strength potion.lua” (if you can’t see the extension, see this post!)
- Open the file with your favourite text editor (or another if you feel rebellious).
The items in a Family of Grave Diggers are all made up like this, a graphic part and a “code” (or script) part.
Come back, it’s really easy to script things!
The file needs 6 functions, this is what make the item tick and moreover it tells the game what to do with it (I put what we’ll use in parentheses).
- What type is it? (see below, but it’s “USE”)
- What kind of characteristic does it give when equipped (we can’t equip it so nothing)
- How many charges does it have if any. (It’s just a one shot so no charges)
- An ingame description. (That’s the hard one!)
- The variation, so for example a weapon can have different variations (no need here though!)
- The scary Function that gets called when the item is used! (see below…)
For the type, there are a bunch of types: USE, EAT, SHOES, HEAD and so on, we’ll use the “USE” type as the player will actually use the item.
The only other specificity is the sixth bulletpoint, the USE function!
Here we can do whatever we want to, spawn a new map, invoke monsters, remove all the hitpoints except one, but lets not do that and instead, add +1 to the players attack:
Well, we are done actually but the item will never drop so we can’t test it…
Let’s insert it in the random drops! Go up two steps to /Mod/Script and open droprandomitem.lua.
It’s a fairly powerful item so lets make it a level 2 item!
Search for “itemlevel2arr” and add it to the list of drops, with a half-low droprate (droprates are just important comparing to other items in the same level, they are not percentages).
Note: the name is the filename without the .lua extension.
Done! Now just play for hours and hope the monster you just killed will drop it!
Or maybe we’ll cheat a little bit to check if we didn’t make some typo when we wrote all those script lines right?
So hold your hat because we are going to cheat!
A little bit.
In the folder where GravbeDiggers.exe lives (one step below /Mod), once you have ran the game and exited normally at least once, you will have 3 save files;
- maps.bin for the maps
- data.xml for running monsters, items, bonuses et al.
- and finally glob.txt which is the most hideous one but it’ll do our deed.
Now just a word of caution, you don’t want to break any of those three files, so
Back them up!
I mean it! If you mess it up, you’ll loose all your progress and the game will just go bananas.
You have been warned!
Let’s calm down and open glob.txt, which is just a ton of variable names and numbers and stuff and search for SHOPITEMS_FOOD
On the line following SHOPITEMS_FOOD, you’ll find a list of all the things the first shopkeeper (the green guy with the cheesy cubes on his head) sells.
The line (warning, never erase or insert a newline in this file!) is composed of a name, a comma, a number (the variation) and a semicolon. Now lets add our potion to the line!
So before it looked like something like this:
And after it will look like this: (you add a semicolon, the name, a comma and a zero)
Save the file, take a deep breath and start the game.
And voilà, the shopkeeper now gives away free potions!
Have fun with an abnormous attack and see you in the next episode!
Ludvig Larsson aka Valmond @ Mindoki Games