Re: Chown

From: Patrick J. Dughi (dughi@IMAXX.NET)
Date: 08/08/97

        Let me quickly make some comments here in the code.

> ACMD(do_chown)
> {
>   struct char_data *victim;
>   struct obj_data *obj;
>   two_arguments(argument, buf, buf2);
>   if (!*buf)
>     send_to_char("Syntax: chown <object> <character>.\r\n", ch);
>   else if (!(victim = get_char_vis(ch, buf2)))
>     send_to_char("No one by that name here.\r\n", ch);
>   else if (victim == ch)
>     send_to_char("Are you sure you're feeling ok?\r\n", ch);
>   else if (GET_LEVEL(victim) >= GET_LEVEL(ch))
>     send_to_char("That's really not such a good idea.\r\n", ch);
>   else if (!*buf2)
>     send_to_char("Syntax: chown <object> <character>.\r\n", ch);

        Whoa. What happened to the object? You never located it. try
something like this:
      if (!(obj = get_obj_in_list_vis(ch, buf, ch->carrying))) {
        sprintf(buf, "You don't seem to have any %ss.\r\n", buf);
        send_to_char(buf, ch);

>   else {
>     act("$n makes a gesture and $p flies from $N to $m.",
>           FALSE,ch,0,0,TO_ROOM);
        Okay.. Uhm. Understand how act() works. .... EVERYONE WHO DOSEN"T

        act takes 6 arguments. Here's what they are:

        1 - String that you're going to send out.
        2 - Boolean value - true/false used to determine if act()s that
are triggered by an invisible person sends out will be seen by those w/o
        3 - The triggering character
        4 - The target object
        5 - The target character (well, could be other, but we'll keep it
simple for now)
        6 - The recievers of the messages....
                the room, the victim, everyone but the victim,  the char,
                and of course, the "TO_SLEEP" which sends even if the guy
                is alseep.
from your code...

>     act("$n makes a gesture and $p flies from $N to $m.",
>           FALSE,ch,0,0,TO_ROOM);

you'd want something like..

      act("$n makes a gesture and $p flies from $N to $m.",

        Else, the program will break when it gets to lookup the name of a
null pointer (it thinks its an object or person...)

>     send_to_char("You make a gesture and $p flies from $N to you.\r\n", ch);
>     send_to_char("$N makes a gesture and $p flies from you to $m.\r\n", victim);    obj_from_char(obj);
        Secondly, send_to_char != act.  It dosen't know anything but the
string, and the person receiving it.  You can't reference a)victims,
b)objects, through it. You CAN do something like

        sprintf(buf,"You make a gesture and %s flies from you to %s\r\n",
        GET_OBJ_NAME(obj), GET_NAME(victim));

 > obj_to_char(obj, ch);

        Now, you also want to probably remove the obj from the character
before you give it to the next person....

> } > }
> only problem is it's saying that obj may be un-initialized.. i thought
> struct did that... *shrug*.. i'll keep working on it :)
        And its uninitilized, because it really is uninitilized.. you
declared space and a name for it in struct, but you never filled it up.
Lucky for you that the functions that I said to add will initilize it with
the needed values huh?

        These are the kind of mistakes I make ever so often, though, not
as frequently as it seems others may =)


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/08/00 PST