That solved the compiling issue.
Any suggestions on troubleshooting the crashing issue?
These parts work- If attempting to forage on wrong terrain type it returns the message you can't forage here.
If player does not have the skill, it returns the message you don't know how.
At the point where the function is determining if an item is found/finding an item it crashes the mud.
I created items using the same item numbers as the original code, so it is possible to find the items.
These are my compiler warnings:
make[1]: Entering directory '/home/kadiya/tbamud/src'
gcc -g -O2 -Wall -Wno-char-subscripts -Wno-unused-but-set-variable -c -o act.other.o act.ot her.c
act.other.c: In function ‘do_forage’:
act.other.c:860:3: warning: suggest parentheses around assignment used as truth value [-Wparen theses]
if(GET_RACE(ch) = RACE_BUBATIN && GET_LEVEL(ch) <= 2)
^~
act.other.c:912:16: warning: passing argument 1 of ‘obj_to_char’ from incompatible pointer typ e [-Wincompatible-pointer-types]
obj_to_char(ch,item_found );
^~
In file included from act.other.c:20:0:
handler.h:33:6: note: expected ‘struct obj_data *’ but argument is of type ‘struct char_data ’
void obj_to_char(struct obj_data *object, struct char_data *ch);
^~~~~~~~~~~
act.other.c:912:19: warning: passing argument 2 of ‘obj_to_char’ from incompatible pointer typ e [-Wincompatible-pointer-types]
obj_to_char(ch,item_found );
^~~~~~~~~~
In file included from act.other.c:20:0:
handler.h:33:6: note: expected ‘struct char_data *’ but argument is of type ‘struct obj_data ’
void obj_to_char(struct obj_data *object, struct char_data *ch);
^~~~~~~~~~~
act.other.c:913:17: warning: passing argument 2 of ‘sprintf’ makes pointer from integer withou t a cast [-Wint-conversion]
sprintf( buf,sizeof(buf),"%sYou have found %s!\r\n", buf, item_found->short_description)
^~~~~~
In file included from /usr/include/stdio.h:29:0,
from sysdep.h:69,
from act.other.c:15:
/usr/include/stdio.h:244:5: note: expected ‘const char * restrict’ but argument is of type ‘lo ng unsigned int’
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
This is the code after modifications for my mud:
Code:
ACMD(do_forage)
{
struct obj_data *item_found = '\0';
int item_no = 10053; /* Initialize with first item poss. */
char buf[MAX_INPUT_LENGTH] = "\0";
if(GET_RACE(ch) = RACE_BUBATIN && GET_LEVEL(ch) <= 2)
{
send_to_char(ch,"You have no idea how to forage for survival!\r\n");
return; }
if(GET_MOVE(ch) < 50)
{
send_to_char(ch,"You do not have enough energy right now.\r\n" );
return; }
if(SECT(ch->in_room) != SECT_FIELD && SECT(ch->in_room) != SECT_FOREST && SECT(ch->in_room) != SECT_HILLS && SECT(ch->in_room) != SECT_MOUNTAIN && SECT(ch->in_room) != SECT_SWAMP)
{
send_to_char(ch, "You cannot forage on this type of terrain!\r\n");
return; }
if(GET_SKILL(ch, SKILL_FORAGE) <= 0)
{
send_to_char(ch,"You have no idea how to forage!\r\n" );
return; }
send_to_char(ch,"You start searching the area for signs of food.\r\n");
act("$n starts foraging the area for food.\r\n", FALSE, ch, 0, 0, TO_ROOM)
;
if(rand_number(1,101) > GET_SKILL(ch, SKILL_FORAGE))
{
WAIT_STATE(ch, PULSE_VIOLENCE * 2);
GET_MOVE(ch) -= (50 - GET_LEVEL(ch));
send_to_char(ch,"\r\nYou have no luck finding anything to eat.\r\n" );
return;
}
else
{
switch (rand_number(1,7))
{
case 1:
item_no = 10053; break; /*<--- Here are the objects you need to code */
case 2: /* Add more or remove some, just change the */
item_no = 10054; break; /* switch(number(1, X) */
case 3:
item_no = 10055; break;
case 4:
item_no = 10056; break;
case 5:
item_no = 10057; break;
case 6:
item_no = 10058; break;
case 7:
item_no = 10059; break;
}
WAIT_STATE( ch, PULSE_VIOLENCE * 2); /* Not really necessary */
GET_MOVE(ch) -= (50 - GET_LEVEL(ch));
item_found = read_object( item_no, VIRTUAL);
obj_to_char(ch,item_found );
sprintf( buf,sizeof(buf),"%sYou have found %s!\r\n", buf, item_found->short_description)
;
send_to_char(ch, buf, item_found );
act("$n has found something in his forage attempt.\r\n", FALSE, ch, 0, 0, TO_ROOM);
return;
}
}