Top Mud Sites Forum Return to TopMudSites.com
Go Back   Top Mud Sites Forum > Mud Development and Administration > MUD Coding
Click here to Register

Reply
 
Thread Tools
Old 09-03-2007, 02:06 AM   #1
tochi
New Member
 
Join Date: Sep 2007
Posts: 4
tochi is on a distinguished road
Unhappy npc summoning code bug (SMAUG)

howdy folks. i'm a bit of an amatuer coder here so be gentle.

we're working on developing a code that'll summon a large NPC to follow the player inside our MUD. basicly summon up a kind of silly homonculus. took bits from animate dead and a pre-existing summon familiar snippet and went to town.

the problem is that for some reason the NPC isn't showing up with the charm flag. it'll follow you, but you can't order it to do a single thing.

there've also been some odd crashes in our test MUD related to this, but the core dumps tell us nothing helpful and the body of the errors are the enigmatic 'called with threadlist_ix -1' sort.

anyway. here's the code itself. if anyone can figure out why the charm flag isn't turning itself on, it'd be great. if you can figure why it appears to make us volitile too, that'd be absotively astonishing.

code's totally free to use and modify, too. :3
Code:
#define MOB_VNUM_DAISY 30807
/* More daisy madness */
ch_ret spell_daisy_daisy( int sn, int level, CHAR_DATA *ch, void *vo )
{
    MOB_INDEX_DATA *pMobIndex;
    CHAR_DATA *mob;
    SKILLTYPE *skill = get_skilltype(sn);
    AFFECT_DATA af;

   if ( ch->pcdata->pet != NULL ) 
   {
       send_to_char("You already have a companion.\n\r",ch);
       failed_casting( skill, ch, NULL, NULL );
       return rSPELL_FAILED;
   }
   if(ch->position == POS_FIGHTING)
   { 
      send_to_char("You can't grow flowers while in fighting!\n\r",ch);
      failed_casting( skill, ch, NULL, NULL );
      return rSPELL_FAILED;
   }
    
   if ( ( pMobIndex = get_mob_index(MOB_VNUM_DAISY) ) == NULL )
   {
       send_to_char( "The daisy mob doesn't exist.\n\r", ch );
       return rSPELL_FAILED;
   }
    
   
    if(ch->in_room->sector_type == SECT_INSIDE 
    || ch->in_room->sector_type == SECT_WATER_SWIM 
    || ch->in_room->sector_type == SECT_WATER_NOSWIM
    || ch->in_room->sector_type == SECT_AIR )
    {
       send_to_char("This doesn't seem like the place to grow daisies...\n\r",ch); 
       failed_casting( skill, ch, NULL, NULL );
       return rSPELL_FAILED;
    }
    
    mob = create_mobile( pMobIndex );
    char_to_room( mob, ch->in_room );
    mob->level      = 1;           
    mob->hit       = mob->max_hit;
    mob->damroll   = ch->level / 8;
    mob->hitroll   = ch->level / 6;
    mob->alignment = ch->alignment;

    act(AT_MAGIC, "$n gardens the ground and grows a daisy!", ch, NULL, NULL, TO_ROOM);
    act(AT_MAGIC, "You garden the ground and grow a daisy!", ch, NULL, NULL, TO_CHAR); 
    
    add_follower( mob, ch );
   /* added some stuff to make the mob your pet */
    mob->leader = ch;
    ch->pcdata->pet = mob;
    xSET_BIT(mob->act, ACT_PET);
    xSET_BIT(mob->affected_by, AFF_CHARM);    
   /* end tochi additions */
    af.type      = sn;
    af.duration  = 0; //We want these to follow indefinitely ~Khtall
    af.location  = 0;
    af.modifier  = 0;
    af.bitvector = meb(AFF_CHARM); 
    affect_to_char( mob, &af );
    
    return rNONE;
    
}
tochi is offline   Reply With Quote
Old 09-03-2007, 02:18 AM   #2
Zeno
Member
 
Zeno's Avatar
 
Join Date: Jan 2005
Location: Saratoga, NY
Home MUD: Bleached InuYasha Galaxy
Posts: 188
Zeno is on a distinguished road
Send a message via AIM to Zeno Send a message via MSN to Zeno Send a message via Yahoo to Zeno
Re: npc summoning code bug (SMAUG)

For one, you don't need the affect_to_char if you already set the affected_by charm.

You also may want to set the mob first before it gets sent to the room, and then add_follower after it gets sent to the room.
Zeno is offline   Reply With Quote
Old 09-03-2007, 02:27 AM   #3
tochi
New Member
 
Join Date: Sep 2007
Posts: 4
tochi is on a distinguished road
Re: npc summoning code bug (SMAUG)

well, i'll give it a shot but i kind of wonder if it'll make a difference.

the tail end of things was a direct copy from animate dead, and the charm flag DID work for animate dead.

from animate dead:
Code:
add_follower( mob, ch );
    af.type      = sn;
    af.duration  = (number_fuzzy( (level + 1) / 4 ) + 1) * DUR_CONV;
    af.location  = 0;
    af.modifier  = 0;
    af.bitvector = meb(AFF_CHARM);
    affect_to_char( mob, &af );
compared to the daisy daisy:
Code:
    add_follower( mob, ch );
   /* added some stuff to make the mob your pet */
    mob->leader = ch;
    ch->pcdata->pet = mob;
    xSET_BIT(mob->act, ACT_PET);
    xSET_BIT(mob->affected_by, AFF_CHARM);    
   /* end tochi additions */
    af.type      = sn;
    af.duration  = 0; //We want these to follow indefinitely ~Khtall
    af.location  = 0;
    af.modifier  = 0;
    af.bitvector = meb(AFF_CHARM);
essentially my additions were redundant. or are you saying that add_follower ought to be after the redundant xset_bits?
tochi is offline   Reply With Quote
Old 09-03-2007, 02:32 AM   #4
Zeno
Member
 
Zeno's Avatar
 
Join Date: Jan 2005
Location: Saratoga, NY
Home MUD: Bleached InuYasha Galaxy
Posts: 188
Zeno is on a distinguished road
Send a message via AIM to Zeno Send a message via MSN to Zeno Send a message via Yahoo to Zeno
Re: npc summoning code bug (SMAUG)

Here is the end of a function I wrote (it works fine). It creates a mob and goes under the control of the person.
Code:
       char_to_room( mob, ch->in_room );
       add_follower( mob, ch );
       xSET_BIT(mob->affected_by, AFF_CHARM);
       ch->mana -= 3000;
       act( AT_PLAIN, "$N rises from the ground!", ch, NULL, mob, TO_CHAR );
       act( AT_PLAIN, "$N rises from the ground!", ch, NULL, mob, TO_ROOM );
       learn_from_success( ch, gsn_spawn_minions );
Mine isn't set as a pet though.

If that doesn't work/help, tell me what message you are getting when you try to order it. Or is it not even getting charmed?
Zeno is offline   Reply With Quote
Old 09-03-2007, 02:35 AM   #5
tochi
New Member
 
Join Date: Sep 2007
Posts: 4
tochi is on a distinguished road
Re: npc summoning code bug (SMAUG)

it is not even getting charmed, that is the issue. i kind of did say that in the first post.
tochi is offline   Reply With Quote
Old 09-03-2007, 02:43 AM   #6
Zeno
Member
 
Zeno's Avatar
 
Join Date: Jan 2005
Location: Saratoga, NY
Home MUD: Bleached InuYasha Galaxy
Posts: 188
Zeno is on a distinguished road
Send a message via AIM to Zeno Send a message via MSN to Zeno Send a message via Yahoo to Zeno
Re: npc summoning code bug (SMAUG)

I know, but I meant is the problem still happening after you made the changes? Followed the order my code is in? Setting the bit should not fail.
Zeno is offline   Reply With Quote
Old 09-03-2007, 03:00 AM   #7
tochi
New Member
 
Join Date: Sep 2007
Posts: 4
tochi is on a distinguished road
Re: npc summoning code bug (SMAUG)

after some tweaking i managed to get it working. your initial suggestion about the char_to_room threw me because i already HAD the add_follower after it, so i thought you must have meant before it and things became messed up.

here's the current working code. i trimmed off some redundancies and nipped the tail end off you mentioned. not sure why it works when prior versions didn't.

Code:
    act(AT_MAGIC, "$n gardens the ground and grows a daisy!", ch, NULL, NULL, TO_ROOM);
    act(AT_MAGIC, "You garden the ground and grow a daisy!", ch, NULL, NULL, TO_CHAR); 
    
   
    add_follower( mob, ch );
   /* added some stuff to make the mob your pet */
    mob->leader = ch;
    ch->pcdata->pet = mob;  
    xSET_BIT(mob->affected_by, AFF_CHARM);  
   /* end tochi additions */


    af.type      = sn;
    af.duration  = 0; //We want these to follow indefinitely ~Khtall
    af.location  = 0;
    af.modifier  = 0;
    af.bitvector = meb(AFF_CHARM); 

    
    return rNONE;
    
}
tochi is offline   Reply With Quote
Old 09-03-2007, 03:43 AM   #8
Zeno
Member
 
Zeno's Avatar
 
Join Date: Jan 2005
Location: Saratoga, NY
Home MUD: Bleached InuYasha Galaxy
Posts: 188
Zeno is on a distinguished road
Send a message via AIM to Zeno Send a message via MSN to Zeno Send a message via Yahoo to Zeno
Re: npc summoning code bug (SMAUG)

You don't need that af.type etc stuff either, since it's never used.
Zeno is offline   Reply With Quote
Reply


Thread Tools


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -4. The time now is 09:24 PM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Style based on a design by Essilor
Copyright Top Mud Sites.com 2014