Date sent: Wed, 16 Jul 1997 18:42:13 -0200 To: "Liner/Nosferatu" From: Rick Rogers (by way of Rick Rogers ) Subject: RCL 3: A small spec example I think some people may be a little confused about everything I've been talking about. Therefore I'm going to give you an example spec so you see how everthing comes together. In this spec we'll have a mob that talks at random and blocks all movement to the east. ------------------ /* spec.example1.c - Specs for Example 1 Written by Ranger for RoninMUD Last Modification Date: Jan 12/97 This spec has the guard (mob # 3999) block all easterly movement. He also says a single message. */ #include #include #include #include #include #include "structs.h" #include "utils.h" #include "comm.h" #include "interpreter.h" #include "handler.h" #include "db.h" #include "spells.h" #include "limits.h" #include "cmd.h" #include "utility.h" #include "act.h" #include "fight.h" #include "spec_assign.h" #include "mob.spells.h" extern struct time_info_data time_info; #define GUARD 3999 int guard_spec(CHAR *guard, CHAR *ch, int cmd, char *arg) { if((GET_POS(guard)==POSITION_STANDING) && (cmd==MSG_MOBACT)) { if(number(0,7)==0) { do_say(guard,"I shall not let anyone pass.", CMD_SAY); return(FALSE); } } /* A few things here. First the GET_POS macro returns the current position of the guard. We make sure the guard is standing when he speaks. We also make sure that the spec is activating on the command for MOBACT which is sent every 10 seconds. Now so we aren't endlessly spammed by the guard speaking, every 10 seconds, we put in a random check. The number function will return a number from 0 to 7 in the above case. It will take the value of 0,1,2,3,4,5,6 or 7. We want it to be 0 to make the guard talk. This is a 1/8 % chance (12.5%). Next is the basic communication of do_say. do_say will cause the guard to talk in the room. From the code, you can see the format it needs. Later I'll introduce you to the extended communication functions. The final thing above is the return FALSE. Since the command activated the spec, we are finished with it and can return to do more things. FALSE means we don't want the code to stop processing the MOBACT command. A return TRUE on TICK or MOBACT would actually stop time. */ if(!ch) return FALSE; /* The rest of this spec has commands which must be input by a player. Thus we make sure a player exists in the ch variable. If ch is 0 (no player) then we return FALSE. This is a fundamental check to prevent crashes. */ if(cmd==CMD_EAST) { do_say(guard,"I said, I shall not let anyone pass!", CMD_SAY); return TRUE; } /* Here we check to see if the player typed "east". If he did then the guard says another message and we return TRUE. By returning TRUE, we tell the code to stop processing the EAST command, and block this command from the main movement function. Then the player doesn't move. */ return FALSE; /* At the end we always return false for all those other commands that we didn't want to check for */ } void assign_guard(void) { assign_mob(GUARD, guard_spec); } /* And we assign the spec to the mob. */ ------------ The end. Rick (Ranger)