Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ HelpDice

HelpDice

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Manakra   (27 posts)  Bio
Date Wed 27 Apr 2005 03:50 AM (UTC)
Message
Heh, if this is been covered before, Me sorry jarjar. Anyways, I would like to make a simple dice object, with a objprog that when user types "roll die numDnum" where both numbs equal a number, then the dice will roll those numbers, add it up, and display to the room.
Top

Posted by Txzeenath   USA  (54 posts)  Bio
Date Reply #1 on Fri 29 Apr 2005 02:43 PM (UTC)

Amended on Fri 29 Apr 2005 02:44 PM (UTC) by Txzeenath

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

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,263 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.