Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex

Members: 0
Guests: 6
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Questions
Forum Rules | Mark all | Recent Posts

Questions
< Newer Topic :: Older Topic >

Pages:<< prev 1, 2 next >>
Post is unread #1 Feb 28, 2012, 8:31 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

So I decided its time to push my limits again and see how much I have improved....
I want to make it where an event happens at 6pm every REAL 3 days... but I am unsure where I would start with that.... or how I would get it to save over automatic reboots...
       
Post is unread #2 Feb 29, 2012, 3:40 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Well, to start, you could probably throw it in events.c.

From there, you'll need to call the current_time and compare it to a set value--not sure how to NOT do this without a starting set value. Then a formula to subtract current time from set time and divide by three, if it returns a whole number, that would be every 3 days. I know the numbers used for time and such are in seconds(?), so you'll need to know how many seconds are in 3 days and divide with that number to get the whole number. And there you have your timer to go off of, at least, to introduce the new event on a 3-day basis.
       
Post is unread #3 Feb 29, 2012, 5:41 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

whats events.c ?
       
Post is unread #4 Feb 29, 2012, 5:48 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

sorry, forgot events were pulled out and put into a separate file for me...

in stock smaug, look under calendar.c, that'd be a good place to start, since a bunch of events are handled in there already that require timing calculations.
       
Post is unread #5 Feb 29, 2012, 6:32 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

Also I have a question about the finger snippet. For some reason when ever u use it on an offline player it will cause the last on timer to reset to the current time... Anyways to fix that?
       
Post is unread #6 Feb 29, 2012, 6:56 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

yeah I looked at that and I have no idea what its doing.... :(
       
Post is unread #7 Mar 1, 2012, 9:48 am   Last edited Mar 1, 2012, 9:57 am by Aurin
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Well, I can at least help you with your timer...this is what I use for people not logging in after 7 days, they get removed from their position and someone else will be thrown in
// Has the person found logged in in the last 7 days?
if(((current_time - roll->lastupdated)/86400) < 7)


If you wanted to check for 3 days, you'd use 60*60*24 = 86400, or 1 day...then you'd want to throw an expression in there like => 3 but < 4 (I don't know an easier way off the top of my head, would have to look that up)...

So, you'd want to change it up to something like this
if(((current_time - setValue)/86400) >= 3 && ((current_time - setValue)/86400) < 4) // This finds out if it's on day 3 or not
{
    setValue = current_time; // We do this so that you'll have the ifcheck within the correct time frame every 3 days
    <put guts of code here>;
}


Now, you'll have to figure out where the setValue is saved, 'cause it can't be within whatever function occupies this. A static file of some sort, like a pfile, is the best place so that setValue is not touched by anything else if not intended to be. We want that value to not change unless the ifcheck goes off.
       
Post is unread #8 Mar 1, 2012, 12:21 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

See i'm not even sure where I would put the timer. I am using smaug if that helps.
       
Post is unread #9 Mar 1, 2012, 1:51 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Okay, looking into this, may have some answers for you..

You'll want to create a new function and we'll place it in calendar.c. at the bottom

You'll need to add that function in the following places:
in mud.h under the calendar.c portion add in a call to the new function at the bottom following the format of the others there
in act_wiz.c under void update_calendar(void), throw in a call to the new function after calc_season(), or before the return, at any rate.

Now, your event should fire at the proper time.

The problem then becomes writing up your function event so that it does what you want it to do. Worry about the calculations and checks later, just get the guts of the event fixed up. Then, you can start messing around with the timer stuff.
       
Post is unread #10 Mar 1, 2012, 3:40 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

Trying to figure out how I want to do these lottery tickets...
       
Post is unread #11 Mar 5, 2012, 3:10 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

How would I go through and clear everything in a file using code? My system should clear the file every 3 days, but can't seem to figure that out.
       
Post is unread #12 Mar 5, 2012, 3:36 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

Also what would I save the timer as under system_data ??? and int or something else?
       
Post is unread #13 Mar 6, 2012, 2:35 am
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

Also I need help with mpsleep...
Here is my GDB report
0x08165afe in mprog_driver (
    com_list=0x889b720 "say Pulse 1\n\rmpsleep 2\n\rsay Pulse 2\n\rmpsleep 3\n\rsay Pulse 2\n\rsay Pulse 4\n\rmpsleep 6\n\r", mob=0x891baa0, actor=0x888bbb0,
    obj=0x0, vo=0x0, single_step=0 '\000') at mud_prog.c:2476
2476             mpsleep->com_list = STRALLOC( command_list );
(gdb) backtrace
#0  0x08165afe in mprog_driver (
    com_list=0x889b720 "say Pulse 1\n\rmpsleep 2\n\rsay Pulse 2\n\rmpsleep 3\n\rsay Pulse 2\n\rsay Pulse 4\n\rmpsleep 6\n\r", mob=0x891baa0, actor=0x888bbb0,
    obj=0x0, vo=0x0, single_step=0 '\000') at mud_prog.c:2476
#1  0x08167b01 in mprog_wordlist_check (arg=0xbfffd126 "test3", mob=0x891baa0,
    actor=0x888bbb0, obj=0x0, vo=0x0, type=1) at mud_prog.c:3021
#2  0x08167bca in mprog_speech_trigger (txt=0xbfffd126 "test3",
    actor=0x888bbb0) at mud_prog.c:3365
#3  0x0806ccb3 in do_say (ch=0x888bbb0, argument=0xbfffd126 "test3";)
    at act_comm.c:896
#4  0x0813d1f5 in interpret (ch=0x888bbb0, argument=0xbfffd126 "test3";)
    at interp.c:627
#5  0x080e1af2 in game_loop () at comm.c:735
#6  0x080e251c in main (argc=Cannot access memory at address 0x488597d6
) at comm.c:367


Code:
void mprog_driver ( char *com_list, CHAR_DATA *mob, CHAR_DATA *actor, OBJ_DATA *obj, void *vo, bool single_step)
{
   CHAR_DATA *rndm = NULL, *vch = NULL;
   MPSLEEP_DATA *mpsleep = NULL;
   char tmpcmndlst[ MAX_STRING_LENGTH ];
   char *command_list; 
   char *cmnd;
  static int prog_nest;
  static int serial;
  int curr_serial;
  ROOM_INDEX_DATA *supermob_room;
    char arg[MIL];
 
  int count = 0, count2 = 0, iflevel = 0, result, ignorelevel = 0;

  OBJ_DATA *true_supermob_obj;
  bool rprog_oprog = ( mob == supermob );
  bool ifstate[MAX_IFS][DO_ELSE + 1];

   if( rprog_oprog )
   {
      serial++;
      supermob_room = mob->in_room;
      true_supermob_obj = supermob_obj;
   }
   else
      true_supermob_obj = NULL, supermob_room = NULL;
   curr_serial = serial;

  
  if IS_AFFECTED( mob, AFF_CHARM )
    return;
    
  /* Next couple of checks stop program looping. -- Altrag */
  if ( mob == actor )
  {
    progbug( "triggering oneself.", mob );
    return;
  }
  
  if ( ++prog_nest > MAX_PROG_NEST )
  {
    progbug( "max_prog_nest exceeded.", mob );
    --prog_nest;
    return;
  }

  /* Make sure all ifstate bools are set to FALSE */
  for ( iflevel = 0; iflevel < MAX_IFS; iflevel++ )
  {
    for ( count = 0; count < DO_ELSE; count++ )
    {
      ifstate[iflevel][count] = FALSE;
    }
  }

   iflevel = 0;
   mprog_online = 0;

  /*
   * get a random visible player who is in the room with the mob.
   *
   *  If there isn't a random player in the room, rndm stays NULL.
   *  If you do a $r, $R, $j, or $k with rndm = NULL, you'll crash
   *  in mprog_translate.
   *
   *  Adding appropriate error checking in mprog_translate.
   *    -Haus
   *
   * This used to ignore players MAX_LEVEL - 3 and higher (standard
   * Merc has 4 immlevels).  Thought about changing it to ignore all
   * imms, but decided to just take it out.  If the mob can see you, 
   * you may be chosen as the random player. -Narn
   *
   */

  count = 0;
  for ( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
    if ( !IS_NPC( vch )
       &&  can_see( mob, vch ) )
      {
        if ( number_range( 0, count ) == 0 )
	  rndm = vch;
        count++;
      }
  
  strcpy( tmpcmndlst, com_list );
  command_list = tmpcmndlst;
 
   /* mpsleep - Restore the environment -rkb */
   if( current_mpsleep )
   {
      ignorelevel = current_mpsleep->ignorelevel;
      iflevel = current_mpsleep->iflevel;

      if( single_step )
         mob->mpscriptpos = 0;

      for( count = 0; count <= MAX_IFS; count++ )
	  {
         for( count2 = 0; count2 < DO_ELSE; count2++ )
            ifstate[count][count2] = current_mpsleep->ifstate[count][count2];
      }

      current_mpsleep = NULL;
   }
   
 if ( single_step )
  {
    if ( mob->mpscriptpos > strlen( tmpcmndlst ) )
       mob->mpscriptpos = 0;
    else
       command_list += mob->mpscriptpos;
    if ( *command_list == '\0' )
    {
	command_list = tmpcmndlst;
	mob->mpscriptpos = 0;
    }
  }

  /* From here on down, the function is all mine.  The original code
     did not support nested ifs, so it had to be redone.  The max 
     logiclevel (MAX_IFS) is defined at the beginning of this file, 
     use it to increase/decrease max allowed nesting.  -Narn 
  */

  while ( TRUE )
  {
    /* With these two lines, cmnd becomes the current line from the prog,
       and command_list becomes everything after that line. */


//      command_list = mprog_one_command( command_list, cmnd );
    cmnd = command_list;
    command_list = mprog_next_command( command_list );


      mprog_online++;

      /* Are we at the end? */
      if( cmnd[0] == '\0' )
      {
         if( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] )
         {
            progbug( "Missing endif", mob );
         }
         --prog_nest;
         return;
      }

 
      /* mpsleep - Check if we should sleep -rkb */
      one_argument( cmnd, arg );
      if( !str_prefix( "mpsleep", cmnd ) )
      {
         if( ( ifstate[iflevel][IN_IF] == ifstate[iflevel][DO_IF]) && ( ifstate[iflevel][IN_ELSE] == ifstate[iflevel][DO_ELSE] ) )
         {
            CREATE( mpsleep, MPSLEEP_DATA, 1 );

            /* State variables */
            mpsleep->ignorelevel = ignorelevel;
            mpsleep->iflevel = iflevel;
            for( count = 0; count < MAX_IFS; count++ )
            {
               for( count2 = 0; count2 < DO_ELSE; count2++ )
               {
                  mpsleep->ifstate[count][count2] =
                  ifstate[count][count2];
               }
            }
         }

         /* Driver arguments */
       Crashing here -------------------->  mpsleep->com_list = STRALLOC( command_list );
         mpsleep->mob = mob;
         mpsleep->actor = actor;
         mpsleep->obj = obj;
         if( mpsleep->obj )
            mpsleep->obj->mpsleep = mpsleep;
         mpsleep->vo = vo;
         mpsleep->single_step = single_step;

  	 /* Time to sleep */
         snprintf( cmnd, sizeof( cmnd ), "%s", one_argument( cmnd, arg ) );
         if( cmnd[0] == '\0' )
            mpsleep->timer = 4;
         else
            mpsleep->timer = atoi( cmnd );;

         if( mpsleep->timer < 1 )
         {
            progbug( "mpsleep - bad arg, using default", mob );
            mpsleep->timer = 4;
         }

         /* Save type of prog, room, object or mob */
         if( mpsleep->mob->pIndexData->vnum == 3 )
         {
            if( !str_prefix( "Room", mpsleep->mob->description ) )
            {
               mpsleep->type = MP_ROOM;
               mpsleep->room = mpsleep->mob->in_room;
            }
            else if( !str_prefix( "Object", mpsleep->mob->description ) )
               mpsleep->type = MP_OBJ;
         }
         else
            mpsleep->type = MP_MOB;

         LINK( mpsleep, first_mpsleep, last_mpsleep, next, prev );

         --prog_nest;
         return;
      }


	  /* Evaluate/execute the command, check what happened. */
    result = mprog_do_command( cmnd, mob, actor, obj, vo, rndm, 
            ( ifstate[iflevel][IN_IF] && !ifstate[iflevel][DO_IF] )
            || ( ifstate[iflevel][IN_ELSE] && !ifstate[iflevel][DO_ELSE] ),
            ( ignorelevel > 0 ) );
if( rprog_oprog )
         uphold_supermob( &curr_serial, serial, &supermob_room, true_supermob_obj );

    /* Script prog support  -Thoric */
    if ( single_step )
    {
      mob->mpscriptpos = command_list - tmpcmndlst;
      --prog_nest;
      return;
    }

    /* This is the complicated part.  Act on the returned value from
       mprog_do_command according to the current logic state. */
    switch ( result )
    {
    case COMMANDOK:
#ifdef DEBUG
log_string( "COMMANDOK" );
#endif
      /* Ok, this one's a no-brainer. */
      continue;
      break;

    case IFTRUE:
#ifdef DEBUG
log_string( "IFTRUE" );
#endif
      /* An if was evaluated and found true.  Note that we are in an
         if section and that we want to execute it. */
      iflevel++;
      if ( iflevel == MAX_IFS )
      {
        progbug( "Maximum nested ifs exceeded", mob );
        --prog_nest;
        return;
      }

      ifstate[iflevel][IN_IF] = TRUE; 
      ifstate[iflevel][DO_IF] = TRUE;
      break;

    case IFFALSE:
#ifdef DEBUG
log_string( "IFFALSE" );
#endif
      /* An if was evaluated and found false.  Note that we are in an
         if section and that we don't want to execute it unless we find
         an or that evaluates to true. */
      iflevel++;
      if ( iflevel == MAX_IFS )
      {
        progbug( "Maximum nested ifs exceeded", mob );
        --prog_nest;
        return;
      }
      ifstate[iflevel][IN_IF] = TRUE; 
      ifstate[iflevel][DO_IF] = FALSE;
      break;

    case ORTRUE:
#ifdef DEBUG
log_string( "ORTRUE" );
#endif
      /* An or was evaluated and found true.  We should already be in an
         if section, so note that we want to execute it. */
      if ( !ifstate[iflevel][IN_IF] )
      {
        progbug( "Unmatched or", mob );
        --prog_nest;
        return;
      }
      ifstate[iflevel][DO_IF] = TRUE;
      break;

    case ORFALSE:
#ifdef DEBUG
log_string( "ORFALSE" );
#endif
      /* An or was evaluated and found false.  We should already be in an
         if section, and we don't need to do much.  If the if was true or
         there were/will be other ors that evaluate(d) to true, they'll set
         do_if to true. */
      if ( !ifstate[iflevel][IN_IF] )
      {
        progbug( "Unmatched or", mob );
        --prog_nest;
        return;
      }
      continue;
      break;

    case FOUNDELSE:
#ifdef DEBUG
log_string( "FOUNDELSE" );
#endif
      /* Found an else.  Make sure we're in an if section, bug out if not.
         If this else is not one that we wish to ignore, note that we're now 
         in an else section, and look at whether or not we executed the if 
         section to decide whether to execute the else section.  Ca marche 
         bien. */
      if ( ignorelevel > 0 )
        continue;

      if ( ifstate[iflevel][IN_ELSE] )
      {
        progbug( "Found else in an else section", mob );
        --prog_nest;
        return;
      }
      if ( !ifstate[iflevel][IN_IF] )
      {
        progbug( "Unmatched else", mob );
        --prog_nest;
        return;
      }

      ifstate[iflevel][IN_ELSE] = TRUE;
      ifstate[iflevel][DO_ELSE] = !ifstate[iflevel][DO_IF];
      ifstate[iflevel][IN_IF]   = FALSE;
      ifstate[iflevel][DO_IF]   = FALSE;
   
      break;

    case FOUNDENDIF:
#ifdef DEBUG
log_string( "FOUNDENDIF" );
#endif
      /* Hmm, let's see... FOUNDENDIF must mean that we found an endif.
         So let's make sure we were expecting one, return if not.  If this
         endif matches the if or else that we're executing, note that we are 
         now no longer executing an if.  If not, keep track of what we're 
         ignoring. */
      if ( !( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] ) )
      {
        progbug( "Unmatched endif", mob );
        --prog_nest;
        return;
      }

      if ( ignorelevel > 0 )      
      {
        ignorelevel--;
        continue;
      }

      ifstate[iflevel][IN_IF]   = FALSE;
      ifstate[iflevel][DO_IF]   = FALSE;
      ifstate[iflevel][IN_ELSE] = FALSE;
      ifstate[iflevel][DO_ELSE] = FALSE;

      iflevel--;
      break;

    case IFIGNORED:
#ifdef DEBUG
log_string( "IFIGNORED" );
#endif
      if ( !( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] ) )
      {
        progbug( "Parse error, ignoring if while not in if or else", mob );
        --prog_nest;
        return;
      }
      ignorelevel++;
      break;

    case ORIGNORED:
#ifdef DEBUG
log_string( "ORIGNORED" );
#endif
      if ( !( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] ) )
      {
        progbug( "Unmatched or", mob );
        --prog_nest;
        return;
      }
      if ( ignorelevel == 0 )
      {
        progbug( "Parse error, mistakenly ignoring or", mob );
        --prog_nest;
        return;
      }

      break;

    case BERR:
#ifdef DEBUG
log_string( "BERR" );
#endif
      --prog_nest;
      return;
      break;
    }
  }
  --prog_nest;
  return;
}


And The Program its Crashing on

>speech_prog test3
say Pulse 1
mpsleep 2
say Pulse 2
mpsleep 3
say Pulse 2
say Pulse 4
mpsleep 6


At first I thought it was just the snippet found on mudbytes for mpsleep, but then I swapped it out for the one here for LOP and the same results.
       
Post is unread #14 Mar 6, 2012, 11:13 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

Anyone have any ideas why?
       
Post is unread #15 Mar 7, 2012, 9:32 am
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Try throwing this in to see if it is the problem
         /* Driver arguments */
if(mpsleep->com_list == NULL)
{
  send_to_char("There is no com_list.\r\n", ch);
  return; // prevents the crash, hopefully
}
if(command_list == NULL)
{
  send_to_char("There is no command_list.\r\n", ch);
  return; // prevents the crash, hopefully
}

       Crashing here -------------------->  mpsleep->com_list = STRALLOC( command_list );
         mpsleep->mob = mob;

One of these is causing the crash, as far as I can tell. This way you'll know which one is causing the problem.
       
Post is unread #16 Mar 7, 2012, 11:33 am
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

Its the com_list. And I need to figure out why...
       
Post is unread #17 Mar 7, 2012, 12:42 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

okay, that was stupid of me...of course mpsleep->com_list would be null, it was never set. heh so the problem is command_list. look back through the function for each instance of command_list and throw in some send_to_char's checking command_list... i.e.
if(command_list == NULL)
{
  send_to_char("Command list is NULL at <however you want to designate the location>.\r\n", ch);
}

Use it liberally to find the problem. :) It should be set on this line:
command_list = tmpcmndlst;

If it's not, then tmpcmdlst was not set properly on the previous line... But, this should give a better start.
       
Post is unread #18 Mar 7, 2012, 2:58 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

This is also a bug that happens in LOP When mpsleep is added.
       
Post is unread #19 Mar 7, 2012, 3:02 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

I replaced it with the old version of mpsleep and it works fine.
       
Post is unread #20 Mar 7, 2012, 4:21 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

Was it just in lop that it crashes there? Or just the lop install etc...
       
Pages:<< prev 1, 2 next >>