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
➜ Function help
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| MattJ820
(32 posts) Bio
|
Date
| Mon 13 Apr 2015 01:41 AM (UTC) Amended on Mon 13 Apr 2015 03:12 AM (UTC) by MattJ820
|
Message
| Hello guys,
I'm trying to write my first function and I'm getting some strange results.
if I type "bountyscan" with no argument, I'm getting a "They aren't here" response rather than the Usage bountyscan <target>
If I bounty scan an NPC, I'm getting the Indetification No match response rather than the you can't scan NPC response.
If I try to bounty scan myself or another player, I get an emergency copy over that prevents the crash so I don' have a core to work with. This is my first function that I pieced together after a view C tutorials and reviewing other functions within bounty.c
Can someone help me figure out what I'm doing wrong?
/* Allows bounty hunters to hunt players by identifying them with a scanner to see if they'e on the bounty list
for situations where they have not been introduced. Object may be required to be worn later..not sure. */
void do_bountyscan ( CHAR_DATA *ch, char *argument)
{
char arg[MAX_STRING_LENGTH];
BOUNTY_DATA *bounty;
CHAR_DATA *victim;
bounty = get_disintegration( victim->name );
if ( IS_NPC(victim))
{
send_to_char( "You cannot bountyscan an NPC\n\r", ch );
return;
}
if ((victim = get_char_room(ch, argument)) == NULL)
{
send_to_char("They aren't here.\n\r", ch);
return;
}
if (argument[0] == '\0' )
{
send_to_char( "Usage: bountyscan <target>\n\r", ch );
return;
}
if ( ch == victim )
{
send_to_char( "Why scan yourself, would you kill yourself for the money?\n\r", ch );
return;
}
if ( bounty != NULL )
{
ch_printf( ch, "Identification: Match! %s has a bounty worth %ld credits.\n\r", victim->name, bounty->amount );
return;
}
if (bounty == NULL)
{
send_to_char( "Identification: No Match!\n\r", ch );
return;
}
} | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #1 on Mon 13 Apr 2015 03:41 AM (UTC) |
Message
| Purely for ease of reading ...
/* Allows bounty hunters to hunt players by identifying them with a scanner to see if they'e on the bounty list
for situations where they have not been introduced. Object may be required to be worn later..not sure. */
void do_bountyscan ( CHAR_DATA *ch, char *argument)
{
char arg[MAX_STRING_LENGTH];
BOUNTY_DATA *bounty;
CHAR_DATA *victim;
bounty = get_disintegration( victim->name );
if ( IS_NPC(victim))
{
send_to_char( "You cannot bountyscan an NPC\n\r", ch );
return;
}
if ((victim = get_char_room(ch, argument)) == NULL)
{
send_to_char("They aren't here.\n\r", ch);
return;
}
if (argument[0] == '\0' )
{
send_to_char( "Usage: bountyscan <target>\n\r", ch );
return;
}
if ( ch == victim )
{
send_to_char( "Why scan yourself, would you kill yourself for the money?\n\r", ch );
return;
}
if ( bounty != NULL )
{
ch_printf( ch, "Identification: Match! %s has a bounty worth %ld credits.\n\r", victim->name, bounty->amount );
return;
}
if (bounty == NULL)
{
send_to_char( "Identification: No Match!\n\r", ch );
return;
}
}
|
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #2 on Mon 13 Apr 2015 03:51 AM (UTC) Amended on Mon 13 Apr 2015 03:55 AM (UTC) by Meerclar
|
Message
| Ok, now that we can read it more easily, let's see if we can find the problem .....
At first glance, I don't see anything obviously wrong in the code, though that doesn't mean much if you missed a declaration. The hotboot you're experiencing would seem to indicate a missed declaration somewhere and while you aren't getting a core dump, you could try running in gdb to get more info on the background processes prior to the hotboot.
As for your scan without an arg returning the "wrong" message, it's a perfectly valid response against a null argument. Take a look at fight.c or magic.c or skills.c and compare the code for checking targets in the room against what you did here. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 13 Apr 2015 06:02 AM (UTC) |
Message
| I think it's the order you are doing it. Check for no argument, before you look up the person in the room. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| MattJ820
(32 posts) Bio
|
Date
| Reply #4 on Mon 13 Apr 2015 04:43 PM (UTC) |
Message
| Changing the order worked. I don't really understand why the order matters, but I guess it does. Proof is in the pudding. Do you have any insight into why so I can understand? I would think the computer would go through all the ifchecks one after another and deliver the appropriate action regardless of the order.
I did it in this order
no argument
victim not in room
victim = self
victim = npc
no bounty
bounty | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Mon 13 Apr 2015 07:56 PM (UTC) |
Message
| Well, you are calling "get_char_room" with an empty argument. It is probably written to respond "they aren't here" in that situation. Otherwise what else could it do? It returns the "victim" variable, so if there is no victim you would then need to test that to be NULL or not. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #6 on Mon 13 Apr 2015 07:57 PM (UTC) |
Message
| Your original code had this, for example:
CHAR_DATA *victim;
bounty = get_disintegration( victim->name );
if ( IS_NPC(victim))
{
send_to_char( "You cannot bountyscan an NPC\n\r", ch );
return;
}
At that point "victim" does not exist, because you haven't found who the victim is, and thus you are lucky it didn't crash when you tried to get the victim name. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| MattJ820
(32 posts) Bio
|
Date
| Reply #7 on Mon 13 Apr 2015 08:50 PM (UTC) |
Message
| That makes sense, thank you. | 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.
23,178 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top