Grant.rtf
docs · 8.6 KB · 2010-03-30
Download « Back to the docs list
{\rtf1\ansi\deff0{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\lang1033\f0\fs20 /***************************************************\par
This code allows IMP's to grant specific imm commands to mortals\par
or lower imms. They can also be revoked with the included revoke\par
command. The granted commands are saved with the player. Also in\par
this snippet is the viewgrant command, which can be used by imps\par
for finding a person's granted commands, or can be used by anyone\par
to view their own granted commands. The maximum number of granted\par
commands is defined as MAX_GRANT, so feel free to change it.\par
****************************************************/\par
\par
-- act_wiz.c --\par
\par
Place these functions anywhere:\par
\par
void do_grant( CHAR_DATA *ch, char *argument )\par
\{\par
char arg1[MAX_INPUT_LENGTH];\par
char arg2[MAX_INPUT_LENGTH];\par
bool found = FALSE;\par
CHAR_DATA *victim;\par
int cmd = 0;\par
int grant = 0;\par
argument = one_argument( argument, arg1 );\par
argument = one_argument( argument, arg2 );\par
\par
if (( arg1[0] == '\\0' ) || ( arg2[0] == '\\0' ))\par
\{\par
send_to_char( "Syntax: grant <player> <command>\\n\\r", ch );\par
return;\par
\}\par
\par
if ( ( victim = get_char_world( ch, arg1 ) ) == NULL )\par
\{\par
send_to_char( "They aren't here.\\n\\r", ch );\par
return;\par
\}\par
if ( IS_NPC(victim))\par
\{\par
\tab send_to_char( "Sorry, no NPC's.\\n\\r", ch );\par
\tab return;\par
\}\par
\par
for ( cmd = 0; cmd_table[cmd].name[0] != '\\0'; cmd++ )\par
\{\par
\tab if ( !str_prefix( arg2, cmd_table[cmd].name ) )\par
\tab\{\par
\tab found = TRUE;\par
\tab break;\par
\tab\}\par
\}\par
if ( !found )\par
\{\par
\tab send_to_char( "That isn't a command.\\n\\r", ch );\par
\tab return;\par
\}\par
found = FALSE;\par
for ( grant = 0; grant < MAX_GRANT; grant++ ) \par
\{\par
\tab if (( victim->pcdata->grant[grant] == NULL ) || ( victim->pcdata->grant[grant][0] == '\\0' ))\par
\tab\{\par
\tab found = TRUE;\par
\tab break;\par
\tab\}\par
\}\par
if (!found)\par
\{\par
\tab send_to_char("They already have too many commands granted.\\n\\r", ch );\par
\tab return;\par
\}\par
victim->pcdata->grant[grant] = str_dup( cmd_table[cmd].name );\par
printf_to_char( ch, "%s has been granted the %s command.\\n\\r", victim->name, cmd_table[cmd].name);\par
printf_to_char( victim, "You have been granted the %s command.\\n\\r", cmd_table[cmd].name);\par
return;\par
\}\par
\par
void do_revoke( CHAR_DATA *ch, char *argument )\par
\{\par
char arg1[MAX_INPUT_LENGTH];\par
char arg2[MAX_INPUT_LENGTH];\par
CHAR_DATA *victim;\par
int grant = 0;\par
argument = one_argument( argument, arg1 );\par
argument = one_argument( argument, arg2 );\par
\par
if (( arg1[0] == '\\0' ) || ( arg2[0] == '\\0' ))\par
\{\par
send_to_char( "Syntax: revoke <player> <command>\\n\\r", ch );\par
return;\par
\}\par
\par
if ( ( victim = get_char_world( ch, arg1 ) ) == NULL )\par
\{\par
send_to_char( "They aren't here.\\n\\r", ch );\par
return;\par
\}\par
if ( IS_NPC(victim))\par
\{\par
\tab send_to_char( "Sorry, no NPC's.\\n\\r", ch );\par
\tab return;\par
\}\par
\par
for ( grant = 0; grant < MAX_GRANT; grant++ )\par
\{\par
\tab if ( victim->pcdata->grant[grant] == NULL)\par
\tab\tab continue;\par
\tab if ( !str_prefix( victim->pcdata->grant[grant], arg2))\par
\tab\{\par
\tab victim->pcdata->grant[grant] = str_dup( "" );\par
\tab printf_to_char( ch, "%s's %s command has been revoked.\\n\\r", victim->name, arg2);\par
\tab printf_to_char( victim, "Your %s command has been revoked.\\n\\r", arg2);\par
\tab return;\par
\tab\}\par
\}\par
send_to_char( "That player has not been granted that command.\\n\\r", ch );\par
return;\par
\}\par
\par
void do_viewgrant( CHAR_DATA *ch, char *argument )\par
\{\par
CHAR_DATA* victim;\par
int i;\par
bool match = FALSE;\par
if ( IS_NPC(ch))\par
\{\par
\tab send_to_char( "Sorry, no NPC's.\\n\\r", ch );\par
\tab return;\par
\}\par
if ( argument[0] == '\\0' )\par
\{\par
\tab send_to_char( "These are your specifically granted commands:\\n\\r", ch );\par
\tab for ( i = 0; i < MAX_GRANT; i++ )\par
\tab\{\par
\tab if (( ch->pcdata->grant[i] != NULL ) && ( ch->pcdata->grant[i][0] != '\\0' ))\par
\tab \{\par
\tab\tab match = TRUE;\par
\tab\tab printf_to_char( ch, "%s\\n\\r", ch->pcdata->grant[i] );\par
\tab \}\par
\tab\}\par
\tab if ( !match )\par
\tab send_to_char( "None.\\n\\r", ch );\par
\tab return;\par
\}\par
\par
if ( ( victim = get_char_world( ch, argument ) ) == NULL )\par
\{\par
send_to_char( "They aren't here.\\n\\r", ch );\par
return;\par
\}\par
if ( IS_NPC(victim))\par
\{\par
\tab send_to_char( "Sorry, no NPC's.\\n\\r", ch );\par
\tab return;\par
\}\par
\par
if ( ch->trust < victim->trust )\par
\{\par
\tab send_to_char( "Your powers aren't strong enough to find their granted commands.\\n\\r", ch );\par
\tab return;\par
\}\par
\par
printf_to_char( ch, "These are %s's specifically granted commands:\\n\\r", victim->name );\par
for ( i = 0; i < MAX_GRANT; i++ )\par
\{\par
\tab if (( victim->pcdata->grant[i] != NULL ) && ( victim->pcdata->grant[i][0] != '\\0' ))\par
\tab\{\par
\tab match = TRUE;\par
\tab printf_to_char( ch, "%s\\n\\r", victim->pcdata->grant[i] );\par
\}\par
\}\par
if ( !match )\par
\tab send_to_char( "None.\\n\\r", ch );\par
return;\par
\}\par
\par
-- interp.c --\par
Add this under "Immortal Commands":\par
\line \{ "grant",\tab\tab do_grant,\tab POS_DEAD,\tab ML, LOG_ALWAYS, 1 \},\par
\{ "revoke",\tab\tab do_revoke,\tab POS_DEAD,\tab ML, LOG_ALWAYS, 1 \},\par
\line Add this under "Informational commands":\par
\line \{ "viewgrant",\tab do_viewgrant, POS_DEAD,\tab 0, LOG_NORMAL, 1 \},\par
\par
At the top of the interpret function add, int i;\line Then scroll down alittle bit and find this:\par
\par
for ( cmd = 0; cmd_table[cmd].name[0] != '\\0'; cmd++ )\par
\{\par
\tab if ( command[0] == cmd_table[cmd].name[0]\par
\tab && !str_prefix( command, cmd_table[cmd].name )\par
\tab && cmd_table[cmd].level <= trust )\par
\par
Remove the cmd_table[cmd].level <= trust condition.\par
\line Add this before the Log and Snoop comment in interpret:\par
\par
if ( cmd_table[cmd].level > trust )\par
\{\par
\tab found = FALSE;\par
\tab for ( i = 0; i < MAX_GRANT; i++ )\par
\tab\{\par
\tab if (( ch->pcdata->grant[i] == NULL ) || ( ch->pcdata->grant[i][0] == '\\0' ))\par
\tab\tab continue;\par
\tab if ( !str_prefix( command, ch->pcdata->grant[i] ))\par
\tab \{\par
\tab\tab found = TRUE;\par
\tab\tab break;\par
\tab \}\par
\tab\}\par
\}\par
\par
-- interp.h --\par
Add these:\par
DECLARE_DO_FUN( do_grant\tab );\par
DECLARE_DO_FUN( do_revoke\tab );\par
DECLARE_DO_FUN( do_viewgrant\tab );\par
\par
-- merc.h --\par
Define this somewhere in with the other MAX values:\par
#define MAX_GRANT\tab\tab 10\par
\par
Add this to the pc_data struct:\par
char *\tab\tab grant[MAX_GRANT];\par
\par
-- save.c --\par
Add this to the top of fwrite_char:\par
\tab int gr;\par
\par
Add after this block of code (toward the end of fwrite_char):\par
\tab for ( gn = 0; gn < MAX_GROUP; gn++ )\par
\{\par
if ( group_table[gn].name != NULL && ch->pcdata->group_known[gn])\par
\{\par
fprintf( fp, "Gr '%s'\\n",group_table[gn].name);\par
\}\par
\}\par
\par
This:\par
\tab for ( gr = 0; gr < MAX_GRANT; gr++ )\par
\tab\{\par
\tab if (( ch->pcdata->grant[gr] != NULL ) && ( ch->pcdata->grant[gr][0] != '\\0' ))\par
\tab \{\par
\tab\tab fprintf( fp, "Cmd %s~\\n",ch->pcdata->grant[gr] );\par
\tab \}\par
\tab\}\par
\par
Add this at the top in fread_char:\par
\tab sh_int grcount;\par
\par
Add this in the logical position in fread_char:\par
\tab if (!str_cmp(word,"Cmd"))\par
\tab \{\par
\tab\tab if (count >= MAX_GRANT)\par
\tab\tab\{\par
\tab\tab fread_to_eol(fp);\par
\tab\tab fMatch = TRUE;\par
\tab\tab break;\par
\tab\tab\}\par
\tab\tab ch->pcdata->grant[grcount] = fread_string( fp );\par
\tab\tab grcount++;\par
\tab\tab fMatch = TRUE;\par
\tab \}\line\par
\par
}