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, 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.
 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ practice/learning/teaching

practice/learning/teaching

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


Pages: 1 2  

Posted by Frobozz   (75 posts)  Bio
Date Fri 31 Dec 2004 01:09 AM (UTC)
Message
Hi!

Right now what Im trying to do is get rid of the do_practice function completely, I already have a "skills" command that breaks different types of skills down into combat/trade/magic/etc... or by damage type. But what I want to do is create a function that allows npc's or pc's to teach a pc a specific skill.

What I can't figure out is how we reach the point where a character has: ch->pcdata->learned[sn].

How would you guys suggest I go about being able to "teach" a pc a skill.

Thanks!
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #1 on Fri 31 Dec 2004 02:26 AM (UTC)
Message
I'm not sure about SMAUG, but SWR has a teach command, you could take a look at that.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #2 on Fri 31 Dec 2004 03:04 AM (UTC)
Message
Thanks,

That pretty much showed me what I was doing wrong.
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #3 on Fri 31 Dec 2004 03:16 AM (UTC)
Message
Hmm well,

Next question!! I've more or less adapted what SWR had, just to get a feel for what it was doing but now I have a more important question!

Now that I have a character obtaining a skill for the first time after being taught, how do I make that save over a hotboot/reboot/etc?

Right now the mud goes down in the next pulse after I use the teach command. Looks something like this:


Program received signal SIGSEGV, Segmentation fault.
0x080eb2a3 in violence_update () at fight.c:387
387                         ch->desc->character->desc = ch->desc;
(gdb) bt
#0  0x080eb2a3 in violence_update () at fight.c:387
#1  0x0818f042 in update_handler () at update.c:2025
#2  0x080c77f9 in game_loop () at comm.c:675
#3  0x080c6d16 in main (argc=2, argv=0xbffffc94) at comm.c:308
#4  0x4003f177 in __libc_start_main (main=0x80c6904 <main>, argc=2, ubp_av=0xbffffc94, init=0x80490dc <_init>, fini=0x8197030 <_fini>,
    rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffffc8c) at ../sysdeps/generic/libc-start.c:129
(gdb) frame 0
#0  0x080eb2a3 in violence_update () at fight.c:387
387                         ch->desc->character->desc = ch->desc;
(gdb) frame 2
#2  0x080c77f9 in game_loop () at comm.c:675
675             update_handler( );
(gdb) frame 3
#3  0x080c6d16 in main (argc=2, argv=0xbffffc94) at comm.c:308
308         game_loop( );
(gdb) frame 4
#4  0x4003f177 in __libc_start_main (main=0x80c6904 <main>, argc=2, ubp_av=0xbffffc94, init=0x80490dc <_init>, fini=0x8197030 <_fini>,
    rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffffc8c) at ../sysdeps/generic/libc-start.c:129
129     ../sysdeps/generic/libc-start.c: No such file or directory.
        in ../sysdeps/generic/libc-start.c


The code I used looks like this:


void do_teach (CHAR_DATA *ch, char *argument)
 {
  char arg[MAX_INPUT_LENGTH];
  char buf[MAX_STRING_LENGTH];
  int sn;

     if ( IS_NPC(ch) )
        return;

    argument = one_argument(argument, arg);

    if ( argument[0] == '\0' )
    {
      send_to_char("\n\r", ch);
      send_to_char("&wSyntax: teach &w<&Cpupil&w> &w<&Cskill&w>\n\r", ch);
      return;
    }
    else
    {
      CHAR_DATA *victim;
      int adept;

    if ( !IS_AWAKE(ch) )
     {
        send_to_char( "You plan on teaching that while sleeping?\n\r", ch );
            return;
     }

    if ( ( victim = get_char_room( ch, arg ) ) == NULL )
        {
            send_to_char( "Your imaginary friend thanks you for the lessons", ch );
            return;
        }

    sn = skill_lookup( argument );

    if ( sn == -1 )
        {
          act( AT_TELL, "You fail in teaching what you do not know.", victim, NULL, ch, TO_VICT );
          return;
        }


    if ( is_name( skill_tname[skill_table[sn]->type], CANT_PRAC ) )
        {
            act( AT_TELL, "You are unable to teach that skill.", victim, NULL, ch, TO_VICT );
            return;
        }

        adept = 5;

    if ( victim->pcdata->learned[sn] >= adept )
        {
            act( AT_TELL, "$n must learn on their own.", victim, NULL, ch, TO_VICT );
            return;
        }
    if ( ch->pcdata->learned[sn] < 5 )
        {
            act( AT_TELL, "You must learn more before teaching others.", victim, NULL, ch, TO_VICT );
            return;
        }
        else
        {
            victim->pcdata->learned[sn] += int_app[get_curr_int(ch)].learn;
            sprintf( buf, "You teach %s &Y$T.&D", victim->name );
            act( AT_ACTION, buf,
                    ch, NULL, skill_table[sn]->name, TO_CHAR );
            sprintf( buf, "%s teaches you &Y$T&D.", ch->name );
            act( AT_ACTION, buf, victim, NULL, skill_table[sn]->name, TO_CHAR );
        }
    }
    return;
}



Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #4 on Fri 31 Dec 2004 04:42 AM (UTC)
Message
Only thing that I can spot offhand would be that that function will wreak havok if called on a non-player victim- after you find the victim character you should make a check with IS_NPC or something. Then again, this would be much more likely to simply segfault than to corrupt data, so it's probably not the problem.

Other than that, you might want to check the values of ch, ch->desc, ch->desc->character and ch->desc->character->desc in the gdb backtrace.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #5 on Fri 31 Dec 2004 07:35 PM (UTC)
Message
These values?



                }
                if (paf->type == gsn_possess)
                {
                    ch->desc->character = ch->desc->original;
                    ch->desc->original  = NULL;
                    ch->desc->character->desc = ch->desc;
                    ch->desc->character->switched = NULL;
                    ch->desc            = NULL;
                }

Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #6 on Fri 31 Dec 2004 10:35 PM (UTC)
Message
Ksilyan was refering to this:
(gdb) frame 0
#0  0x080eb2a3 in violence_update () at fight.c:387
387     
Print those in your gdb to see what they are and why its crashing at that spot.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #7 on Fri 31 Dec 2004 11:00 PM (UTC)
Message
Like this?


(gdb) print ch
$1 = (CHAR_DATA *) 0x83fdb38
(gdb) print ch->desc
$2 = (DESCRIPTOR_DATA *) 0x83fbb00
(gdb) print ch->desc->character
$3 = (CHAR_DATA *) 0x0
(gdb) print ch->desc->character->desc
Cannot access memory at address 0x4c
(gdb)


Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #8 on Fri 31 Dec 2004 11:38 PM (UTC)

Amended on Fri 31 Dec 2004 11:39 PM (UTC) by Nick Cash

Message
Quote:


Program received signal SIGSEGV, Segmentation fault.
0x080eb2a3 in violence_update () at fight.c:387
387 ch->desc->character->desc = ch->desc;


--------
gdb) print ch->desc->character
$3 = (CHAR_DATA *) 0x0

This would make perfect sense. You are trying to access something from a NULL pointer, which quite obviously wont work :P

I'm not quite sure what that has to do with the skills though...

~Nick Cash
http://www.nick-cash.com
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #9 on Fri 31 Dec 2004 11:49 PM (UTC)
Message
Indeed. That's your problem, but how you got there baffles me. Surely something has changed besides this one function, because the function you showed us doesn't even touch the descriptor structures.

If you haven't already done so, be sure to make clean, then make again.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #10 on Sat 01 Jan 2005 12:16 AM (UTC)
Message
Well the violence update refers to the section under gsn_possess. I had taken this skill off the skill table, would that cause this crash?
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #11 on Sat 01 Jan 2005 12:42 AM (UTC)
Message
Hmm.

I put possess back into the skills table (ie skills.dat) and the crash stopped happening. Now why is this so? I have absolutely zero idea.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #12 on Sat 01 Jan 2005 02:11 AM (UTC)
Message
You say that the update function refers to the possess skill... could you show me how? It's possible that you're trying to edit a skill that doesn't exist, thereby editing memory that isn't what you think it is, and thereby corrupting something - for instance, a player descriptor.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Frobozz   (75 posts)  Bio
Date Reply #13 on Sat 01 Jan 2005 03:12 AM (UTC)
Message
line 387 of fight.c where it was breaking is a part of this:


                }
                if (paf->type == gsn_possess)
                {
                    ch->desc->character = ch->desc->original;
                    ch->desc->original  = NULL;
                    ch->desc->character->desc = ch->desc;
                    ch->desc->character->switched = NULL;
                    ch->desc            = NULL;
                }


Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #14 on Sat 01 Jan 2005 03:29 AM (UTC)
Message
Check ch->desc->original, that would seem to be null. If thats the case, you need to find out why that if check is evaluating to true. When you removed it, did you remove all references to possess? Looks like gsn_possess might be doubling up with something else, and this is mistaking the affect type as possess instead of what it really is.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
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.


44,001 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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.