Coding Class: Dagger
From LSWiki
(Difference between revisions)
Revision as of 12:02, 1 May 2008 (edit) Matts (Talk | contribs) ← Previous diff |
Revision as of 21:35, 8 May 2008 (edit) Matts (Talk | contribs) Next diff → |
||
Line 1: | Line 1: | ||
- | In this initial section we are going to be an item from the ground up; in this case a dagger (everyone loves to stab). Commented code examples will appear followed by a 'notes' section below the example. Any further elaboration on that particular section I will place there, and any discussion regarding that particular section should go there as well. | ||
- | |||
// Include our base header file | // Include our base header file | ||
#include <item.h> | #include <item.h> | ||
// Inherit our base object for what we're creating | // Inherit our base object for what we're creating | ||
inherit "/std/item"; | inherit "/std/item"; | ||
- | |||
// configure() is where we define what the object -is-, and indirectly what it does. | // configure() is where we define what the object -is-, and indirectly what it does. | ||
void configure() { | void configure() { | ||
+ | // Call the configure() function from the file we inherited above. This really only calls one other function but it's necessary so that everything we're about to do works. | ||
::configure(); | ::configure(); | ||
+ | // Call set_weapon_type() in the weapon extension and set it to Weapon_Type_Dagger (since we're making a dagger!) | ||
weapon()->set_weapon_type(Weapon_Type_Dagger); | weapon()->set_weapon_type(Weapon_Type_Dagger); | ||
+ | // Set the craft of the item. | ||
set_craft(Craft_Good); | set_craft(Craft_Good); | ||
+ | // Setup a general default description. | ||
add_description(Description_Type_Generic); | add_description(Description_Type_Generic); | ||
+ | // Setup the materials and forms and parts that we want our dagger to be made of. | ||
add_proportion(([ | add_proportion(([ | ||
Element_Type : Material_Iron, | Element_Type : Material_Iron, | ||
Line 18: | Line 20: | ||
} | } | ||
- | ==== Notes ==== | + | ==== Important Header Files ==== |
+ | /lib/craft.h - Craft_Good | ||
+ | /lib/item.h | ||
+ | /lib/materials.h - Material_Iron | ||
+ | /lib/weapons.h - Weapon_Type_Dagger | ||
+ | /lib/descriptors/description.h - Description_Type_Generic | ||
+ | /lib/descriptors/element.h - Element_Type, Element_Proportion | ||
+ | |||
+ | ==== Important Source Files ==== | ||
+ | /obj/extensions/weapon.c | ||
+ | /std/item.c | ||
+ | |||
+ | ==== Code Discussion ==== |
Revision as of 21:35, 8 May 2008
// Include our base header file #include <item.h> // Inherit our base object for what we're creating inherit "/std/item"; // configure() is where we define what the object -is-, and indirectly what it does. void configure() { // Call the configure() function from the file we inherited above. This really only calls one other function but it's necessary so that everything we're about to do works. ::configure(); // Call set_weapon_type() in the weapon extension and set it to Weapon_Type_Dagger (since we're making a dagger!) weapon()->set_weapon_type(Weapon_Type_Dagger); // Set the craft of the item. set_craft(Craft_Good); // Setup a general default description. add_description(Description_Type_Generic); // Setup the materials and forms and parts that we want our dagger to be made of. add_proportion(([ Element_Type : Material_Iron, Element_Proportion : 1.0, ])); }
Important Header Files
/lib/craft.h - Craft_Good /lib/item.h /lib/materials.h - Material_Iron /lib/weapons.h - Weapon_Type_Dagger /lib/descriptors/description.h - Description_Type_Generic /lib/descriptors/element.h - Element_Type, Element_Proportion
Important Source Files
/obj/extensions/weapon.c /std/item.c