Re: Mob_Special_Procedures

From: Wout Mertens (Wout.Mertens@rug.ac.be)
Date: 04/15/96


On Mon, 15 Apr 1996, Fionn Colvin wrote:

> int *obj_give(int mob_num, int obj_num)
> {
>   int ogive = -1;
> 
>   switch (mob_num) {
>     case [put mob vnum here]:
>       if obj_num = [put vnum here] {
>          ogive = [put item vnum here];
>          return (ogive);
>          break;
>       else if obj_num = [put next vnum here] {
>          ogive = [put item vnum here];
>          return (ogive);
>          break;
>       else {
>          return (ogive);
>          break;

A few things: you forgot to end your if {    } (note the }!)
and switch is nestable, so you can put
switch mob
  case mob
    switch obj
      case obj

etc...

>     default:
>       return (ogive);
>   }
> }
> 
> 
> SPECIAL(give_item)
> {
>    int item_get = -1;
>    int item_give = -1;
>    int mob_num;
> 
>    if ([item given to mob]) {
This is a toughie. The special is called before the actual command is done,
so the only thing you know is that the player gives something, with
CMD_IS("give"). Problem with that is that the player could be giving to 
someone else. So you should call do_give, with the correct parameters, 
(which you can find in the define of ACMD and SPECIAL, sorry, it's 
getting late here...) and then see if your inventory changed. If it 
changed, the pointer to your inventory is the object that is given (I 
hope, but this is the way it is done the whole time in Circle, so...), so 
you can check if it was changed with a temp. Then you know the object and 
as such the rest of the program.
A few important points:
in the define of SPECIAL you will see amongst other things a void* me. me 
is the mob/obj/room that is doing the special, IF THERE IS A COMMAND! 
Otherwise, it is null. (Mobs get called every so often to refresh etc)
So you should check if the command is not 0, then if it is give.

Second point: A SPECIAL should return TRUE or FALSE, FALSE when it did 
not process the command.
So when it was give and you passed it to do_give, don't forget to return 
TRUE. Otherwise, return FALSE.

so your code would be:
if (!cmd_num)  /* or whatever that variable was again */
  return FALSE;

if (CMD_IS("give")) {
  save pointer
  run do_give
  check pointer
  <your stuff>
  return TRUE;
} else
  return FALSE;

Gekke Eekhoorn of BUG.



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