Jake Turner This code is an automated auction system, a player auctions an item stating a set price or it defaults to the objects price. Then other players can bid on it, until it is sold, or not sold.." I hope it helps, if you have any questions or problems please email me at jakehturner@hotmail.com, or find me on ICQ #64284941. I will not be responsible if anything happens if you install this code anywhere, use it at your own risks. (not that it should :P) Heh, and i dont care if you mention me or not seems as you'd prolly be able to write this yourself ;). But if you feel the need im Jake Turner aka Culhaven (sword.grailhall.com - port 2411). %%%%%%%%%%%%%%%%%%%%%%%%%%% The commands are as follows. auction [minimum bid] - begins auction of item auction - stops the current auction, if immortal confiscates auctioned object auction - get stats on current item for 500 gold person who is selling cant find out stats bid - bids on current object, must be 10% more than current bid auctalk - replace old 'auction' function, used to speak on the auction channel. %%%%%%%%%%%%%%%%%%%%%%%%%%% ------------- act.item.c ------------- /* Local Variables */ int curbid = 0; /* current bid on item being auctioned */ int aucstat = AUC_NULL_STATE; /* state of auction.. first_bid etc.. */ struct obj_data *obj_selling = NULL; /* current object for sale */ struct char_data *ch_selling = NULL; /* current character selling obj */ struct char_data *ch_buying = NULL; /* current character buying the object */ char *auctioneer[AUC_BID + 1] = { "The auctioneer auctions, '$n puts $p up for sale at %d coins.'", "The auctioneer auctions, '$p at %d coins going once!.'", "The auctioneer auctions, '$p at %d coins going twice!.'", "The auctioneer auctions, 'Last call: $p going to $n for %d coins.'", "The auctioneer auctions, 'Unfortunately $p is unsold, returning it to $n.'", "The auctioneer auctions, 'SOLD! $p to $n for %d coins!.'", "The auctioneer auctions, 'Sorry, $n has cancelled the auction.'", "The auctioneer auctions, 'Sorry, $n has left us, the auction can't go on.'", "The auctioneer auctions, 'Sorry, $p has been confiscated, shame on you $n.'", "The auctioneer tells you, '$n is selling $p for %d gold.'", "The auctioneer auctions, '$n bids %d coins on $p.'" }; /* Extern Vars */ extern struct descriptor_data *descriptor_list; /* Local functions */ void start_auction(struct char_data * ch, struct obj_data * obj, int bid); void auc_stat(struct char_data * ch, struct obj_data *obj); void stop_auction(int type, struct char_data * ch); void check_auction(void); void auc_send_to_all(char *messg, bool buyer); ACMD(do_auction); ACMD(do_bid); void start_auction(struct char_data * ch, struct obj_data * obj, int bid) { /* Take object from character and set variables */ obj_from_char(obj); obj_selling = obj; ch_selling = ch; ch_buying = NULL; curbid = bid; /* Tell th character where his item went */ sprintf(buf, "%s magic flies away from your hands to be auctioned!\r\n", obj_selling->short_description); CAP(buf); send_to_char(buf, ch_selling); /* Anounce the item is being sold */ sprintf(buf, auctioneer[AUC_NULL_STATE], curbid); auc_send_to_all(buf, FALSE); aucstat = AUC_OFFERING; } void check_auction(void) { switch (aucstat) { case AUC_NULL_STATE: return; case AUC_OFFERING: { sprintf(buf, auctioneer[AUC_OFFERING], curbid); CAP(buf); auc_send_to_all(buf, FALSE); aucstat = AUC_GOING_ONCE; return; } case AUC_GOING_ONCE: { sprintf(buf, auctioneer[AUC_GOING_ONCE], curbid); CAP(buf); auc_send_to_all(buf, FALSE); aucstat = AUC_GOING_TWICE; return; } case AUC_GOING_TWICE: { sprintf(buf, auctioneer[AUC_GOING_TWICE], curbid); CAP(buf); auc_send_to_all(buf, FALSE); aucstat = AUC_LAST_CALL; return; } case AUC_LAST_CALL: { if (ch_buying == NULL) { sprintf(buf, auctioneer[AUC_LAST_CALL]); CAP(buf); auc_send_to_all(buf, FALSE); sprintf(buf, "%s flies out the sky and into your hands.\r\n", obj_selling->short_description); CAP(buf); send_to_char(buf, ch_selling); obj_to_char(obj_selling, ch_selling); /* Reset auctioning values */ obj_selling = NULL; ch_selling = NULL; ch_buying = NULL; curbid = 0; aucstat = AUC_NULL_STATE; return; } else { sprintf(buf, auctioneer[AUC_SOLD], curbid); auc_send_to_all(buf, TRUE); /* Give the object to the buyer */ obj_to_char(obj_selling, ch_buying); sprintf(buf, "%s flies out the sky and into your hands, what a steel!\r\n", obj_selling->short_description); CAP(buf); send_to_char(buf, ch_buying); sprintf(buf, "Congrats! You have sold %s for %d coins!\r\n", obj_selling->short_description, curbid); send_to_char(buf, ch_selling); /* Give selling char the money for his stuff */ GET_GOLD(ch_selling) += curbid; /* Reset auctioning values */ obj_selling = NULL; ch_selling = NULL; ch_buying = NULL; curbid = 0; aucstat = AUC_NULL_STATE; return; } } } } ACMD(do_auction) { char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; struct obj_data *obj; int bid = 0; two_arguments(argument, arg1, arg2); if (!*arg1) { send_to_char("Auction what?\r\n", ch); return; } else if (is_abbrev(arg1, "cancel") || is_abbrev(arg1, "stop")) { if ((ch != ch_selling && GET_LEVEL(ch) < LVL_GRGOD) || aucstat == AUC_NULL_STATE) { send_to_char("You're not even selling anything!\r\n", ch); return; } else if (ch == ch_selling) { stop_auction(AUC_NORMAL_CANCEL, NULL); return; } else { stop_auction(AUC_WIZ_CANCEL, ch); } } else if (is_abbrev(arg1, "stats") || is_abbrev(arg1, "identify")) { auc_stat(ch, obj_selling); return; } else if (!(obj = get_obj_in_list_vis(ch, arg1, ch->carrying))) { sprintf(buf, "You don't seem to have %s %s.\r\n", AN(arg1), arg1); send_to_char(buf, ch); return; } else if (!*arg2 && (bid = obj->obj_flags.cost) <= 0) { sprintf(buf, "What should be the minimum bid?\r\n"); send_to_char(buf, ch); return; } else if (*arg2 && (bid = atoi(arg2)) <= 0) { send_to_char("Come on? One coin at least?\r\n", ch); return; } else if (aucstat != AUC_NULL_STATE) { sprintf(buf, "Sorry, but %s is already auctioning %s at %d coins!\r\n", GET_NAME(ch_selling), obj_selling->short_description, bid); send_to_char(buf, ch); return; } else if (OBJ_FLAGGED(obj, ITEM_NOSELL)) { send_to_char("Sorry but you can't sell that!\r\n", ch); return; } else { send_to_char(OK, ch); start_auction(ch, obj, bid); return; } } ACMD(do_bid) { char arg[MAX_INPUT_LENGTH]; int bid; if(IS_NPC(ch)) return; one_argument(argument, arg); if (!*arg) { send_to_char("Bid yes, good idea, but HOW MUCH??\r\n", ch); return; } else if(aucstat == AUC_NULL_STATE) { send_to_char("Thats very enthusiastic of you, but nothing is being SOLD!\r\n", ch); return; } else if(ch == ch_selling) { send_to_char("Why bid on something your selling? You can 'cancel' the auction!\r\n", ch); return; } else if((bid = atoi(arg)) < ((int) curbid * 1.1 - 1) && ch_buying != NULL) { sprintf(buf, "You must bid at least 10 percent more than the current bid. (%d)\r\n", (int) (curbid * 1.1)); send_to_char(buf, ch); return; } else if(ch_buying == NULL && bid < curbid) { sprintf(buf, "You must at least bid the minimum!\r\n"); send_to_char(buf, ch); return; } else if(bid > GET_GOLD(ch)) { send_to_char("You don't have that much gold!\r\n", ch); return; } else { if (ch == ch_buying) GET_GOLD(ch) -= (bid - curbid); else { GET_GOLD(ch) -= bid; if(!(ch_buying == NULL)) GET_GOLD(ch_buying) += curbid; } curbid = bid; ch_buying = ch; sprintf(buf, auctioneer[AUC_BID], bid); auc_send_to_all(buf, TRUE); aucstat = AUC_OFFERING; return; } } void stop_auction(int type, struct char_data * ch) { switch (type) { case AUC_NORMAL_CANCEL: { sprintf(buf, auctioneer[AUC_NORMAL_CANCEL]); auc_send_to_all(buf, FALSE); break; } case AUC_QUIT_CANCEL: { sprintf(buf, auctioneer[AUC_QUIT_CANCEL]); auc_send_to_all(buf, FALSE); break; } case AUC_WIZ_CANCEL: { sprintf(buf, auctioneer[AUC_WIZ_CANCEL]); auc_send_to_all(buf, FALSE); break; } default: { send_to_char("Sorry, that is an unrecognised cancel command, please report.", ch); return; } } if (type != AUC_WIZ_CANCEL) { sprintf(buf, "%s flies out the sky and into your hands.\r\n", obj_selling->short_description); CAP(buf); send_to_char(buf, ch_selling); obj_to_char(obj_selling, ch_selling); } else { sprintf(buf, "%s flies out the sky and into your hands.\r\n", obj_selling->short_description); CAP(buf); send_to_char(buf, ch); obj_to_char(obj_selling, ch); } if (!(ch_buying == NULL)) GET_GOLD(ch_buying) += curbid; obj_selling = NULL; ch_selling = NULL; ch_buying = NULL; curbid = 0; aucstat = AUC_NULL_STATE; } void auc_stat(struct char_data *ch, struct obj_data *obj) { if (aucstat == AUC_NULL_STATE) { send_to_char("Nothing is being auctioned!\r\n", ch); return; } else if (ch == ch_selling) { send_to_char("You should have found that out BEFORE auctioning it!\r\n", ch); return; } else if (GET_GOLD(ch) < 500) { send_to_char("You can't afford to find the stats on that, it costs 500 coins!\r\n", ch); return; } else { /* auctioneer tells the character the auction details */ sprintf(buf, auctioneer[AUC_STAT], curbid); send_to_char(CCRED(ch, C_SPR), ch); act(buf, TRUE, ch_selling, obj, ch, TO_VICT | TO_SLEEP); send_to_char(CCNRM(ch, C_SPR), ch); GET_GOLD(ch) -= 500; call_magic(ch, NULL, obj_selling, SPELL_IDENTIFY, 30, CAST_SPELL); } } void auc_send_to_all(char *messg, bool buyer) { struct descriptor_data *i; if (messg == NULL) return; for (i = descriptor_list; i; i = i->next) { if (PRF_FLAGGED(i->character, PRF_NOAUCT)) continue; send_to_char(CCMAG(i->character, C_SPR), i->character); if (buyer) act(messg, TRUE, ch_buying, obj_selling, i->character, TO_VICT | TO_SLEEP); else act(messg, TRUE, ch_selling, obj_selling, i->character, TO_VICT | TO_SLEEP); send_to_char(CCNRM(i->character, C_SPR), i->character); } } -------------- interpreter.c -------------- ACMD(do_action); ACMD(do_bid); --- Search for: { "auction" , POS_SLEEPING, do_gen_comm , 0, SCMD_AUCTION }, And replace it with: { "auction" , POS_RESTING , do_auction , 0, 0 }, { "auctalk" , POS_SLEEPING, do_gen_comm , 0, SCMD_AUCTION }, --- Search for: { "beg" , POS_RESTING , do_action , 0, 0 }, And below it add: { "bid" , POS_RESTING , do_bid , 0, 0 }, ------------- act.other.c ------------- /* External Variables */ extern struct char_data *ch_selling; extern struct char_data *ch_buying; /* Extern procedures */ void stop_auction(int type, struct char_data * ch); --- Search for: send_to_char("Goodbye, friend.. Come back soon!\r\n", ch); And below it add: if (ch == ch_selling) stop_auction(QUIT_CANCEL, NULL); --- ------------- structs.h ------------- /* Auctioning states */ #define AUC_NULL_STATE 0 /* not doing anything */ #define AUC_OFFERING 1 /* object has been offfered */ #define AUC_GOING_ONCE 2 /* object is going once! */ #define AUC_GOING_TWICE 3 /* object is going twice! */ #define AUC_LAST_CALL 4 /* last call for the object! */ #define AUC_SOLD 5 /* Auction cancle states */ #define AUC_NORMAL_CANCEL 6 /* normal cancellation of auction */ #define AUC_QUIT_CANCEL 7 /* auction canclled because player quit */ #define AUC_WIZ_CANCEL 8 /* auction cancelled by a god */ /* Other auctioneer functions */ #define AUC_STAT 9 #define AUC_BID 10 ------ Search for: #define PULSE_VIOLENCE (2 RL_SEC) Below it add: #define PULSE_AUCTION (9 RL_SEC) ----- ------------ comm.c ------------ /* external functions */ void check_auction(void); ----- Search for: if (!(pulse % PULSE_MOBILE)) mobile_activity(); Below it add: if (!(pulse % PULSE_AUCTION)) check_auction(); -----