26 Feb, 2008, goran wrote in the 1st comment:
Votes: 0
I have been messing around with my do_score command and
am trying to do something like this
Immune: disease
Resist: charm
Vulnerable: acid
Affected by: invisible detect_invis sanctuary flying
I am trying to display the Immune, Resist, Vulnerable and affected by
flags that the player has based on race and I cannot figure out how
to do this.

Any ideas or help would be excellent!

Goran
26 Feb, 2008, Davion wrote in the 2nd comment:
Votes: 0
Take a look at do_mstat it pretty much has everything you want.
if (victim->imm_flags)
{
sprintf(buf, "Immune: %s\n\r",imm_bit_name(victim->imm_flags));
send_to_char(buf,ch);
}

if (victim->res_flags)
{
sprintf(buf, "Resist: %s\n\r", imm_bit_name(victim->res_flags));
send_to_char(buf,ch);
}

if (victim->vuln_flags)
{
sprintf(buf, "Vulnerable: %s\n\r", imm_bit_name(victim->vuln_flags));
send_to_char(buf,ch);
}



And
if (victim->affected_by)
{
sprintf(buf, "Affected by %s\n\r",
affect_bit_name(victim->affected_by));
send_to_char(buf,ch);
}
26 Feb, 2008, goran wrote in the 3rd comment:
Votes: 0
Yes! It was in the same file I was working with the
whole time :) Thank you.

I am also trying to setup score to show how long a player
has played during their session.

Example:
You have been playing for 1 hour, 32 minutes and 12 seconds this session.

I understand how to get the current hours just not the rest..
(current_time - ch->logon)) / 3600);
26 Feb, 2008, Davion wrote in the 4th comment:
Votes: 0
goran said:
I understand how to get the current hours just not the rest..


Do you? This is how you get how many hours they've played.

( ch->played + (int) (current_time - ch->logon) ) / 3600)


The ch->logon is the time that they logged into the MUD, so (current_time - ch->logon) is the amount of time (in seconds) that has passed since they logged in.
26 Feb, 2008, goran wrote in the 5th comment:
Votes: 0
I shouldn't have used 'current' rather played. I understand

current_time - ch->logon / 3600

will give me hours that the user has played. What I don't understand is how
to get the minutes and seconds played from that.
27 Feb, 2008, David Haley wrote in the 6th comment:
Votes: 0
If you don't divide by 3600, you have total seconds. So, get the remainder of a division by 3600 and you get seconds left over from the conversion to hours. Similarly for minutes except obviously you need to use a different number than 3600.
28 Feb, 2008, Conner wrote in the 7th comment:
Votes: 0
I'll clarify for you, Goran, since they both told you the answer but didn't explain it. :wink:
current_time - ch->logon / 3600 = hours_played because current_time - ch->logon = seconds_played so, current_time - ch->logon % 3600 will be seconds_played less the last full hour_played, take that number / 60 = minutes_played (less hours_played) and (current_time - ch->logon / 3600) - (current_time - ch->logon % 3600) = seconds_played (less than a full minute).. following so far?

Hmm, let's try this another way.

int seconds_played, minutes_played, hours_played;

hours_played = current_time - ch->logon / 3600;
minutes_played = ( current_time - ch->logon / 60 ) - ( hours_played * 60 );
seconds_played = ( current_time - ch->logon ) - ( ( hours_played * 3600 ) + ( minutes_played * 60 ) );


Better?
28 Feb, 2008, David Haley wrote in the 8th comment:
Votes: 0
That last + should be a minus, I believe. (i.e., take all seconds, and then remove the seconds from the hours, and then remove the seconds from the minutes)
28 Feb, 2008, Conner wrote in the 9th comment:
Votes: 0
Hmm, I was thinking we're subtracting the sum of the seconds that make up hours & minutes from the total to get the remaining seconds. *shrug*
28 Feb, 2008, David Haley wrote in the 10th comment:
Votes: 0
Example: 3800 seconds

–> 1 hour, 3 minutes and 20 seconds.

3800 / 3600 = 1 hour.
3800/60 - 1*60 = 3 minutes.
3800 - 1*3600 - 3*60 = 20 seconds

but,
3800 - 1*3600 + 3*60 = 380
which is not the right number of seconds.
28 Feb, 2008, David Haley wrote in the 11th comment:
Votes: 0
Ergh… I didn't notice the parentheses around the addition. Sorry, my bad!
29 Feb, 2008, Conner wrote in the 12th comment:
Votes: 0
No problem, once you start getting more than a couple of sets of parenthesis they can be pretty hard to follow sometimes. :)
29 Feb, 2008, kiasyn wrote in the 13th comment:
Votes: 0
from Drazon
char * display_timer( int timer, bool shortTime )
{
int day, hour, min, sec;
static char stime[MSL];

day = timer/86400;
hour = (timer/3600)%24;
min = (timer%3600)/60;
sec = timer%60;

stime[0] = '\0';
if ( day > 0 )
sprintf( stime, "%d%s%s", day, shortTime ? "d" : " day", day == 1 || shortTime ? "" : "s" );
if ( hour > 0 )
sprintf( stime + strlen(stime), "%s%d%s%s",
day && !shortTime ? " " : "", hour, shortTime ? "h" : " hour",
hour == 1 || shortTime ? "" : "s" );
if ( min > 0 )
sprintf( stime + strlen(stime), "%s%d%s%s",
(day || hour) && !shortTime ? ", " : "", min, shortTime ? "m" : " minute",
min != 1 && !shortTime ? "s" : "" );
if ( sec > 0 )
sprintf( stime + strlen(stime), "%s%d%s%s",
(day || hour || min) && !shortTime ? ", " : "", sec, shortTime ? "s" : " second",
sec != 1 && !shortTime ? "s" : "" );
return stime;
}
29 Feb, 2008, Kayle wrote in the 14th comment:
Votes: 0
The one from my code is not quite as simple as Kiasyn's but it works.

/* Calling function must insure tstr buffer is large enough.
* Returns the address of the buffer passed, allowing things like
* this printf example: 123456secs = 1day 10hrs 17mins 36secs
* time_t tsecs = 123456;
* char buff[ MSL ];
*
* printf( "Duration is %s\n", duration( tsecs, buff ) );
*/

#define DUR_SCMN ( 60 )
#define DUR_MNHR ( 60 )
#define DUR_HRDY ( 24 )
#define DUR_DYWK ( 7 )
#define DUR_ADDS( t ) ( (t) == 1 ? '\0' : 's' )

char *sec_to_hms( time_t loctime, char *tstr )
{
time_t t_rem;
int sc, mn, hr, dy, wk;
int sflg = 0;
char buff[MSL];

if( loctime < 1 )
{
mudstrlcat( tstr, "no time at all", MSL );
return ( tstr );
}

sc = loctime % DUR_SCMN;
t_rem = loctime - sc;

if( t_rem > 0 )
{
t_rem /= DUR_SCMN;
mn = t_rem % DUR_MNHR;
t_rem -= mn;

if( t_rem > 0 )
{
t_rem /= DUR_MNHR;
hr = t_rem % DUR_HRDY;
t_rem -= hr;

if( t_rem > 0 )
{
t_rem /= DUR_HRDY;
dy = t_rem % DUR_DYWK;
t_rem -= dy;

if( t_rem > 0 )
{
wk = t_rem / DUR_DYWK;

if( wk )
{
sflg = 1;
snprintf( buff, MSL, "%d week%c", wk, DUR_ADDS( wk ) );
mudstrlcat( tstr, buff, MSL );
}
}
if( dy )
{
if( sflg == 1 )
mudstrlcat( tstr, " ", MSL );
sflg = 1;
snprintf( buff, MSL, "%d day%c", dy, DUR_ADDS( dy ) );
mudstrlcat( tstr, buff, MSL );
}
}
if( hr )
{
if( sflg == 1 )
mudstrlcat( tstr, " ", MSL );
sflg = 1;
snprintf( buff, MSL, "%d hour%c", hr, DUR_ADDS( hr ) );
mudstrlcat( tstr, buff, MSL );
}
}
if( mn )
{
if( sflg == 1 )
mudstrlcat( tstr, " ", MSL );
sflg = 1;
snprintf( buff, MSL, "%d minute%c", mn, DUR_ADDS( mn ) );
mudstrlcat( tstr, buff, MSL );
}
}
if( sc )
{
if( sflg == 1 )
mudstrlcat( tstr, " ", MSL );
snprintf( buff, MSL, "%d second%c", sc, DUR_ADDS( sc ) );
mudstrlcat( tstr, buff, MSL );
}
return ( tstr );
}
29 Feb, 2008, Guest wrote in the 15th comment:
Votes: 0
Nice. I think I like Kiasyn's version of that better. :)
29 Feb, 2008, Kayle wrote in the 16th comment:
Votes: 0
Well, you wrote the one I posted. XD It's from the Calendar part of the weather system. >.>
29 Feb, 2008, Guest wrote in the 17th comment:
Votes: 0
I didn't write it though. Vor did, a long time ago. It worked and we just never looked at it again :)
29 Feb, 2008, kiasyn wrote in the 18th comment:
Votes: 0
mine has the option (shorttime) to display time like 12d3h22m11s as well as 12 days, 3 hours, 22 minutes, 11 seconds
01 Mar, 2008, David Haley wrote in the 19th comment:
Votes: 0
Instead of nesting all the ifs like that, you could do something like this:

if (t_rem > 0) {
nest nest nest
}


becomes

if (trem <= 0) {
return;
}
the rest of the code goes here


It would make the control flow a little easier to follow.
03 Mar, 2008, Guest wrote in the 20th comment:
Votes: 0
Heh. Or I could just hijack Kiasyn's code if he doesn't mind me using it :P
0.0/22