Coding Class: Dagger

From LSWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 21:37, 8 May 2008 (edit)
Matts (Talk | contribs)
(Important Header Files)
← Previous diff
Revision as of 21:42, 8 May 2008 (edit)
Matts (Talk | contribs)

Next diff →
Line 1: Line 1:
-// Include our base header file 
#include <item.h> #include <item.h>
- // 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. 
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 35: Line 27:
==== Important Source Files ==== ==== Important Source Files ====
 +* /def/material/i/iron.c
 +* /def/weapon_type/d/dagger.c
* /obj/extensions/weapon.c * /obj/extensions/weapon.c
* /std/item.c * /std/item.c
==== Code Discussion ==== ==== Code Discussion ====
 +So the above code is the bare bones minimal effort it takes to create a code-current basic iron dagger. If you're an older coder you may notice several things missing that you are used to. Namely some type of set_id() or set_names(), set_weapon_class() and other such things. The reason we don't need them here is because we are using the power of [[definitions]] to our advantage. We tell the object that it's a dagger weapon made of iron and the game can figure out what to call it, how to color it, what weapon class, penetration, attack speed, weight and value it needs to have; among other things. You can get an idea of how this is possible by checking out the /def/* files listed above. Feel free to browse around while you're in there and get a feel of what's defined and what isn't.

Revision as of 21:42, 8 May 2008

#include <item.h>
inherit "/std/item";
void configure() {
    ::configure();
    weapon()->set_weapon_type(Weapon_Type_Dagger);
    set_craft(Craft_Good);
    add_description(Description_Type_Generic);
    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

  • /def/material/i/iron.c
  • /def/weapon_type/d/dagger.c
  • /obj/extensions/weapon.c
  • /std/item.c

Code Discussion

So the above code is the bare bones minimal effort it takes to create a code-current basic iron dagger. If you're an older coder you may notice several things missing that you are used to. Namely some type of set_id() or set_names(), set_weapon_class() and other such things. The reason we don't need them here is because we are using the power of definitions to our advantage. We tell the object that it's a dagger weapon made of iron and the game can figure out what to call it, how to color it, what weapon class, penetration, attack speed, weight and value it needs to have; among other things. You can get an idea of how this is possible by checking out the /def/* files listed above. Feel free to browse around while you're in there and get a feel of what's defined and what isn't.

Personal tools