Once again, I find myself posting a prototype system that I've written, to see 
if anybody likes it/wants to use it.  It's not tested a whole lot, although 
I've experimented with different components for different machines, which will 
be described later in the document.  The system is a machine system, which 
allows a player to 'use' a machine to create something.  For example, feeding 
some sparkly dust and a special herb into a healing potion machine will cause 
the machine to create a healing potion.  Here's the 'use' function:

void do_use( CHAR_DATA *ch, char *argument )
{
    char buf[MSL];
    OBJ_DATA * machine;
    OBJ_DATA * create = NULL;
    OBJ_DATA * components[MAX_COMPONENTS];
    OBJ_DATA * obj;
    OBJ_INDEX_DATA * theindex;
    bool all_comps_found = 0;
    int i;
    int comp_num = 0;
    int j = 1;
    
    if ((machine = get_obj_carry(ch, argument, ch)) == NULL)
    {
        sprintf(buf, "You haven't got a %s.\n\r",argument);
        send_to_char(buf,ch);
        return;
    }
    
    if (machine->item_type != ITEM_MACHINE)
    {
        send_to_char("That is not a machine.\n\r",ch);
        return;
    }
    
    theindex = get_obj_index( machine->value[0] );
    if (theindex != NULL)
    if ((create = create_object(theindex, 0 )) == NULL)
    {
        send_to_char("That machine seems to be broken.\n\r",ch);
        return;
    }
    
    
    for (i = 0; i < MAX_COMPONENTS; i++)
    {
        theindex = get_obj_index( machine->value[j] );
        if (theindex != NULL)
          components[i] = create_object(theindex,0);
        else
          components[i] = NULL;
        j++;
    }
    
    for (i = 0; i < MAX_COMPONENTS; i++)
    {
        if (components[i] != NULL)
          comp_num++;
        else
          break;
    }
    
    for (i = 0; i < comp_num; i++)
    {
        if (get_obj_carry(ch, components[i]->name, ch) != NULL)
          all_comps_found = 1;
        else
        {
          all_comps_found = 0;
          break;
        }
    }
    
    if (!all_comps_found)
    {
        send_to_char("You don't have all the necessary components for this 
machine.\n\r",ch);
        return;
    }
    
    for (i = 0; i < comp_num; i++)
    {
        obj = get_obj_carry(ch, components[i]->name, ch);
        if (obj != NULL)
        {
            extract_obj(obj);
            sprintf(buf, "You use up %s.\n\r",obj->short_descr);
            send_to_char(buf,ch);
        }
    }
    
    if (create != NULL)
    {
        obj_to_char( create,ch );
        sprintf(buf, "You have created %s with %s!\n\r", create->short_descr, 
machine->short_descr);
        send_to_char(buf, ch);
    }
    
    return;
}

in merc.h:
Be sure to define MAX_COMPONENTS as 4 (4 works well, as there's 5 values to an 
object and one of them is reserved for the vnum of the object to be created.)  
Also, don't forget to define ITEM_MACHINE.

Example area file entries for two different machines:

#40
coffee machine maker~
a coffee machine~
A coffee machine is here.~
~
machine 0 A
3101 3011 0 0 0
0 0 0 P

#30019
healing potion machine~
a healing potion machine~
A healing potion machine lies here.~
metal~
machine 0 A
3080 3383 1378 0 0
24 100 50000 P

Here's how the values are allocated:

v0: vnum of obj to be created
v1: component 1
v2: component 2
v3: component 3
v4: component 4

NOTE:  "Component" refers to an "ingredient" that must be used to create the 
desired object.

Syntax for the use command: use <machine name>

So far this system has worked pretty well, but with only limited testing.  
Anyone is welcome to use it (no pun intended) or try it out.  You can even 
report bugs/suggestions/comment to me at [EMAIL PROTECTED] if you want to, but 
that's completely optional, as is providing credit to me.


Enjoy,
Thori



Reply via email to