Second-Hand Shops [by Jake Turner]
Snippet Posted Tuesday, August 1st @ 12:29:47 PM, by Brandon Brown in the Specials dept.
Jake Turner writes, "Ok, this is a small clean mobprog i made that turns a normal mob into a dealer in second hand items. People can leave there eq with the mob at a price then other people can buy it, the money is then donated to the sellers bank account. "
Ok, this is a small clean mobprog i made that turns a normal mob into 
a dealer in second hand items.  People can leave there eq with the mob 
at a price then other people can buy it, the money is then donated to 
the sellers bank account. 

IMPORTANT: make a directory in lib called 'tellas'
this is where the object information will be saved feel free to change 
the directory name.. but make sure you edit the code too :P

Here is the code, add it to a new file:

To use it just assign a mob to the pawn_keeper
prog in spec_assigns.

############################################
############################################
############################################


/* Code for second hand shops
     by Jake Turner - aka Culhaven (sword.grailhall.com port2411)
*/

#include "conf.h"
#include "sysdep.h"

#include "structs.h"
#include "screen.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "tellas.h"
#include "spells.h"

extern struct index_data *mob_index;
extern struct index_data *obj_index;
extern struct obj_data *obj_proto;
extern obj_rnum top_of_objt;
extern struct descriptor_data *descriptor_list;
obj_rnum find_obj_rnum(obj_vnum vnum);
extern FILE *player_fl;

ACMD(do_say);


SPECIAL(pawn_keeper)
{
     FILE *fl;
     char file_name[100];
     struct char_data *customer;
     struct obj_data *obj;
     struct tella_data item, temp, *list = NULL;
     int number, nr, j, found = FALSE;
     char arg[MAX_INPUT_LENGTH];
     char arg2[MAX_INPUT_LENGTH];
     obj_rnum rnum = NOTHING;
     struct char_file_u temp_u;
     struct descriptor_data *d;
          
     if(!cmd || (
          !CMD_IS("list") &&
          !CMD_IS("sell") &&
          !CMD_IS("buy"))
          )
          return FALSE;

     customer = ch;
     ch = (struct char_data *) me;

     sprintf(file_name, "tellas/%d", GET_MOB_VNUM(ch));

     switch(LOWER(*cmd_info[cmd].command))
     {
     case 'l': /* List*/ /* List*/ /* List*/ /* List*/ /* List*/ /* List*/ /* List*/
          number = 0;

          if(!(fl = fopen(file_name, "rb")))
          {
               do_say(ch, "There is currently nothing for sale here.", 0, 0);
               return (TRUE);
          }

          if(!*argument)
          {
               send_to_char("&wNo. Item                                             Asking Price        Sellers Name&n\r\n", customer);
               send_to_char("&c-------------------------------------------------------------------------------------&n\r\n", customer);

               while(!feof(fl))
               {
                    fread(&item, sizeof(struct tella_data), 1, fl);     
                    if(feof(fl))
                         break;

                    if((rnum = find_obj_rnum(item.vnum)) == NOTHING)
                         continue;

                    sprintf(buf, "%-4d%-50s%-20d%s\r\n", ++number, obj_proto[rnum].short_description, item.sell_price,
                         item.seller_name);
                    send_to_char(buf, customer);
               }
               fclose(fl);
          }
          else
          {
               one_argument(argument, arg);
               if((number = atoi(arg)) < 0)
               {
                    send_to_char("Posotive number please.\r\n", customer);
                    return TRUE;
               }

               if(GET_GOLD(customer) < 750)
               {
                    do_say(ch, "You don't have enough gold to get stats on that item.\r\n", 0, 0);
                    return(TRUE);
               }

               nr = 0;

               while(!feof(fl))
               {
                    fread(&item, sizeof(struct tella_data), 1, fl);
                    if(feof(fl))
                         break;

                    if(++nr == number)
                         break;
               }
               
               if(feof(fl))
               {
                    do_say(ch, "I don't have that many items in stock!", 0, 0);
                    fclose(fl);
                    return (TRUE);
               }

               obj = read_object(item.vnum, VIRTUAL);
               obj->obj_flags.value[0] = item.value[0];
               obj->obj_flags.value[1] = item.value[1];
               obj->obj_flags.value[2] = item.value[2];
               obj->obj_flags.value[3] = item.value[3];
               obj->obj_flags.extra_flags = item.extra_flags;
               obj->obj_flags.bitvector = item.bitvector;
               obj->obj_flags.weight = item.weight;
               for (j = 0; j < MAX_OBJ_AFFECT; j++)
                    obj->affected[j] = item.affected[j];
               obj->obj_flags.timer = item.timer;                    
               
               GET_GOLD(customer) -= 750;
               act("$n takes your gold and begins to tell you about $p.", FALSE, ch, obj, customer, TO_VICT);
               act("$n takes $N's gold and begins to tell $M about $p.", FALSE, ch, obj, customer, TO_NOTVICT);
               call_magic(customer, 0, obj, SPELL_IDENTIFY, 50, CAST_SPELL);
               fclose(fl);
               return (TRUE);
          }
          return (TRUE);
     case 's':
          two_arguments(argument, arg, arg2);
          
          if(!*arg || !*arg2)
          {
               send_to_char("Syntax: sell  \r\n", customer);
               return(TRUE);
          }

          if(!(obj = get_obj_in_list_vis(customer, arg, customer->carrying)))
          {
               do_say(ch, "You havn't even got that!", 0, 0);
               return(TRUE);
          }

          if((number = atoi(arg2)) < 0)
          {
               do_say(ch, "Not a negative price please!", 0, 0);
               return(TRUE);
          }

          memset(&item, 0, sizeof(struct tella_data));
          item.value[0] = obj->obj_flags.value[0];
          item.value[1] = obj->obj_flags.value[1];
          item.value[2] = obj->obj_flags.value[2];
          item.value[3] = obj->obj_flags.value[3];

          item.extra_flags = obj->obj_flags.extra_flags;
          item.bitvector = obj->obj_flags.bitvector;
          item.weight = obj->obj_flags.weight;
     
          for (j = 0; j < MAX_OBJ_AFFECT; j++)
                         item.affected[j] = obj->affected[j];

          item.timer = obj->obj_flags.timer;
          item.sell_price = number;
          item.seller_id = GET_IDNUM(customer);
          sprintf(item.seller_name, GET_NAME(customer));
          item.vnum = GET_OBJ_VNUM(obj);
          

          number = 0;
          if(!(fl = fopen(file_name, "rb")))
               number = 0;
          else
          {
               while(!feof(fl))
               {
                    fread(&temp, sizeof(struct tella_data), 1, fl);
                    if(feof(fl))
                         break;

                    number++;
               }
          

               CREATE(list, struct tella_data, number);
               rewind(fl);
               number = 0;
               while(!feof(fl))
               {
                    fread(&temp, sizeof(struct tella_data), 1, fl);     

                    if(feof(fl))
                              break;

                    memcpy(&list[number++], &temp, sizeof(struct tella_data));
               }
               fclose(fl);
          }
          
          if(!(fl = fopen(file_name, "wb")))
          {
               do_say(ch, "Sorry my door is jammed into the store room.", 0, 0);
               log("SYSERR: Can't open file for writing in tellas - sell.");
               if(list)
                    free(list);
               return(TRUE);
          }
          
          if(number)
               for(j = 0; j < number; j++)
                    fwrite(&list[j], sizeof(struct tella_data), 1, fl);

          if(list)
               free(list);

          fwrite(&item, sizeof(struct tella_data), 1, fl);

          fclose(fl);
          
          do_say(ch, "Ok I'll keep hold of that one for you, I'll take 10% of the profit mind!", 0, 0);
          act("You hand $n $p.", FALSE, ch, obj, customer, TO_VICT);
          act("$N hands $n $p.", FALSE, ch, obj, customer, TO_NOTVICT);
          obj_from_char(obj);
          extract_obj(obj);
          return(TRUE);
     case 'b':
          number = 0;
          if(!*argument)
          {
               send_to_char("Syntax: buy \r\n", customer);
               return(TRUE);
          }

          one_argument(argument, arg);
          if(!isdigit(arg[0]))
          {
               do_say(ch, "Please use the number of the object for reference, not the name.", 0, 0);
               return(TRUE);
          }
          else if((nr = atoi(arg)) < 0)
          {
               do_say(ch, "A posotive number please!", 0, 0);
               return(TRUE);
          }
          
          if(!(fl = fopen(file_name, "rb")))
          {
               do_say(ch, "I don't have anything for sale right now.", 0, 0);
               return(TRUE);
          }
          else
          {
               while(!feof(fl))
               {
                    fread(&temp, sizeof(struct tella_data), 1, fl);
                    if(feof(fl))
                         break;

                    number++;
               }
          }

          if(nr > number)
          {
               do_say(ch, "I don't think i have that many items in my store!", 0, 0);
               fclose(fl);
               return(TRUE);
          }

          CREATE(list, struct tella_data, number);
          rewind(fl);
          number = 0;
          while(!feof(fl))
          {
               fread(&temp, sizeof(struct tella_data), 1, fl);

               if(feof(fl))
                         break;

               memcpy(&list[number++], &temp, sizeof(struct tella_data));
          }
          fclose(fl);

          if(GET_GOLD(customer) < list[nr - 1].sell_price &&
               GET_IDNUM(customer) != list[nr - 1].seller_id)
          {
               do_say(ch, "Hah, you're too poor go away!", 0, 0);
               return(TRUE);
          }

          memcpy(&item, &list[nr - 1], sizeof(struct tella_data));

          if(!(fl = fopen(file_name, "wb")))
          {
               do_say(ch, "Sorry my door is jammed into the store room.", 0, 0);
               log("SYSERR: Can't open file for writing in tellas - sell.");
               return(TRUE);
          }

          for(j = 0; j < number; j++)
               if(j != nr - 1)
                    fwrite(&list[j], sizeof(struct tella_data), 1, fl);

          fclose(fl);

          obj = read_object(item.vnum, VIRTUAL);
          obj->obj_flags.value[0] = item.value[0];
          obj->obj_flags.value[1] = item.value[1];
          obj->obj_flags.value[2] = item.value[2];
          obj->obj_flags.value[3] = item.value[3];
          obj->obj_flags.extra_flags = item.extra_flags;
          obj->obj_flags.bitvector = item.bitvector;
          obj->obj_flags.weight = item.weight;
          for (j = 0; j < MAX_OBJ_AFFECT; j++)
               obj->affected[j] = item.affected[j];
          obj->obj_flags.timer = item.timer;
          
          
          if(GET_IDNUM(customer) != item.seller_id)
          {
               GET_GOLD(customer) -= list[nr - 1].sell_price;
               do_say(ch, "Good deal!", 0, 0);
               act("$n hands you $p.", FALSE, ch, obj, customer, TO_VICT);
               act("$n hands $N $p.", FALSE, ch, obj, customer, TO_NOTVICT);

               found = FALSE;
               for (d = descriptor_list; d; d = d->next)
               {
                    if(STATE(d) != CON_PLAYING)
                         continue;
                    if(GET_IDNUM(d->character) == item.seller_id)
                    {
                         found = TRUE;
                         sprintf(buf, "A man runs in and informs you that $N has bought $p for %d coins.\r\n", item.sell_price);
                         sprintf(buf + strlen(buf), "He also says you received %d gold from the sale which has been deposited in your bank account.",
                              ((item.sell_price / 10) * 9));
                         act(buf, FALSE, d->character, obj, customer, TO_CHAR);
                         act("A man runs in and talks to $n.", FALSE, d->character, 0, 0, TO_ROOM);
                         send_to_room("The man turns and is gone as fast as he entered.\r\n", d->character->in_room);
                         GET_BANK_GOLD(d->character) += ((item.sell_price / 10) * 9);
                    }
               }

               if(!found)
               {
                    number = 0;

                    if (!(fl = fopen(PLAYER_FILE, "r+")))
                         do_say(ch, "Well, I can't seem to find the sellers accounts, ah well, their loss.", 0, 0);
                    else
                         while(!feof(fl))
                         {
                              fread(&temp_u, sizeof(struct char_file_u), 1, fl);     

                              if(temp_u.char_specials_saved.idnum == item.seller_id)
                              {
                                   act("$n deposits some money into a jar.", FALSE, ch, 0, 0, TO_ROOM);
                                   temp_u.points.bank_gold += ((item.sell_price / 10) * 9);
                                   temp_u.player_specials_saved.sold_in_tellas += 1;
                                   fseek(player_fl, number * sizeof(struct char_file_u), SEEK_SET);
                                   fwrite(&temp_u, sizeof(struct char_file_u), 1, player_fl);
                                   break;
                              }
                              number++;

                         }

               }

          }
          else
          {
               do_say(ch, "Here, you don't want to sell it anymore? Have it back then!", 0, 0);
               act("$n hands you $p.", FALSE, ch, obj, customer, TO_VICT);
               act("$n hands $N $p.", FALSE, ch, obj, customer, TO_NOTVICT);
          }
          
          obj_to_char(obj, customer);
          save_char(customer, NOWHERE);
          free(list);
          return (TRUE);
          
     }               

     return(FALSE);
}


obj_rnum find_obj_rnum(obj_vnum vnum)
{
     int i;

     for(i = 0; i < top_of_objt; i++)
          if(obj_index[i].vnum == vnum)
               return i;
     return NOTHING;
}



<< Disarm Skill [by BoxBoy] | Reply | Flattened | Vampires and Slayers [by BoxBoy] >>

 


Related Links
  Jake Turner
Related Articles
More by bbrown
 
 

Quick Links
 
The CircleMUD FAQ
The CircleMUD home page
Alex's Snippets
Wintermute Snippets
CircleMUD Bug Reporting or Help
CircleMUD List Archives
CircleMUD Resources
Death Gate's Scripts
(Author of C conversion)
Sammy's code site
Erwin S. Andreasen's page
(Author of mudFTP and other goodies)
Death's Gate Scripting site
Help for CircleMUD in Windows
The OasisOLC Maintenance Effort
George's Random Stuff
Imaginary Realities
MUD Dictionary
 
 


Pawn Shops Snippet
by Dana Luther (dtluther@mindspring.com) on Monday, August 14th @ 10:08:34 AM
http://
The snippet #includes a file - tellas.h which has not been posted with the snippet.
[ Reply to this comment ]

tellas.h?
by Ryan Schwan (aderon@aderon.battlegroundz.com) on Saturday, August 19th @ 02:35:10 PM
http://aderon.battlegroundz.com
I was wondering where the tellas.h was. Is this from some other patch or version that I don't have?
[ Reply to this comment ]
      Re: tellas.h? by Jake Turner on Saturday, August 18th @ 06:39:53 AM