Posted by
| Txzeenath
USA (54 posts) Bio
|
Message
| Hmm you mean like this? Pulled from act_obj.c so not sure how it will work with your current code.
Simply do "cedit rolldie create do_rolldie" than set an item to the type "chance".
void
do_rolldie (CHAR_DATA * ch, char *argument)
{
OBJ_DATA *die;
char output_string[MAX_STRING_LENGTH];
char roll_string[MAX_STRING_LENGTH];
char total_string[MAX_STRING_LENGTH];
char *verb;
/*
* char* face_string = NULL; char** face_table = NULL;
*/
int rollsum = 0;
int roll_count = 0;
int numsides;
int numrolls;
bool *face_seen_table = NULL;
if (IS_NPC (ch))
{
send_to_char ("Huh?\n\r", ch);
return;
}
if ((die =
get_eq_char (ch, WEAR_HOLD)) == NULL || die->item_type != ITEM_CHANCE)
{
ch_printf (ch, "You must be holding an item of chance!\n\r");
return;
}
numrolls = (is_number (argument)) ? atoi (argument) : 1;
verb = get_chance_verb (die);
if (numrolls > 100)
{
ch_printf (ch, "You can't %s more than 100 times!\n\r", verb);
return;
}
numsides = die->value[0];
if (numsides <= 1)
{
ch_printf (ch, "There is no element of chance in this game!\n\r");
return;
}
if (die->value[3] == 1)
{
if (numrolls > numsides)
{
ch_printf (ch,
"Nice try, but you can only %s %d times.\n\r",
verb, numsides);
return;
}
face_seen_table = calloc (numsides, sizeof (bool));
if (!face_seen_table)
{
bug
("do_rolldie: cannot allocate memory for face_seen_table array, terminating.\n\r",
0);
return;
}
}
sprintf (roll_string, " ");
while (roll_count++ < numrolls)
{
int current_roll;
char current_roll_string[MAX_STRING_LENGTH];
do
{
current_roll = number_range (1, numsides);
}
while (die->value[3] == 1 && face_seen_table[current_roll - 1] == TRUE);
if (die->value[3] == 1)
face_seen_table[current_roll - 1] = TRUE;
rollsum += current_roll;
if (roll_count > 1)
strcat (roll_string, ", ");
if (numrolls > 1 && roll_count == numrolls)
strcat (roll_string, "and ");
if (die->value[1] == 1)
{
char *face_name = get_ed_number (die, current_roll);
if (face_name)
{
char *face_name_copy = strdup (face_name); /* Since
* I
* want
* to
* tokenize
* without
* modifying
* the
* original
* string
*/
sprintf (current_roll_string, "%s",
strtok (face_name_copy, "\n"));
free (face_name_copy);
}
else
sprintf (current_roll_string, "%d", current_roll);
}
else
sprintf (current_roll_string, "%d", current_roll);
strcat (roll_string, current_roll_string);
}
if (numrolls > 1 && die->value[2] == 1)
{
sprintf (total_string, ", for a total of %d", rollsum);
strcat (roll_string, total_string);
}
strcat (roll_string, ".\n\r");
sprintf (output_string, "You %s%s", verb, roll_string);
act (AT_GREEN, output_string, ch, NULL, NULL, TO_CHAR);
sprintf (output_string, "$n %s%s", verb, roll_string);
act (AT_GREEN, output_string, ch, NULL, NULL, TO_ROOM);
if (face_seen_table)
free (face_seen_table);
return;
}
|
Darkness comes along thy path, searching, wanting, calling wrath,
shadows awaken, release the light, one and only.. here to fight,
challenge the darkness, the shadows they call, hunting the living,
more and all. Roaring thunder, full of hate, a single bound, seals
your fate.
-Txzeenath
telnet://divineright.org:8088
Alumuble Arda -
*Player owned shops, clans, and housing
*Multiclass & Stat training
*Random mob name generation implemented and Overland mapping.
*Realistic equipment statistics
*Interactive enviroment(weather/sectors)
*Weapon sheaths(scabbards), Throwing weapons
*Automatic crash recovery, saving, and reporting without disconnecting
*Fully customizeable color, Automapper, "Smart" mobiles, Hiscore tables, and more!
Currently running AGE v1.9.6(Originated and modified from Smaug 1.4a) | Top |
|