Author Topic: Fix for /lib/shop.c  (Read 1198 times)

Offline hells

  • Acquaintance
  • *
  • Posts: 11
    • View Profile
Fix for /lib/shop.c
« on: June 03, 2012, 09:41:41 PM »
If your vendor is one that may wander off or be killed by players then performing a list, show, price, or appraise will cause an error. This is due to the shop.c calling present("vendor")->cmdBrowse(). There is no verification that present returned a non-zero so an error is raised when the shop keep is out.

Code: [Select]
/*    /realms/haderach/land/cities/hartland/pawnshop.c
 *    created by Haderach@Frontiers
 *    Date: Sat Aug 31 02:37:27 1996
 */

#include <lib.h>

inherit LIB_ROOM;

static void create(){
    ::create();
}

void init(){
    ::init();
    add_action("list","list");
    add_action("show","show");
    add_action("price","price");
    add_action("appraise","appraise");
}

object *ob;
object ob2;
int list(string str){
    if(!str || str == "") str = "all";
    if (present("vendor"))
        present("vendor")->cmdBrowse(this_player(),str);
    else
        return 0;
    return 1;
}



int show(string str){
    if (present("vendor"))
        present("vendor")->cmdShow(this_player(),str);
    else
        return 0;
    return 1;
}

int price(string str){
    if (present("vendor"))
        present("vendor")->cmdPrice(this_player(),str);
    else
        return 0;
    return 1;
}

int appraise(string str){
    if (present("vendor"))
        present("vendor")->cmdAppraise(this_player(),str);
    else
        return 0;
    return 1;
}


Simple fix just put's an if statement around it and returns 0 if they are out. You may want to get fancy and have it return a message to the players that the shop is closed or some such thing.

Feel free to use this as you like. Public Domain and all that stuff.