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
➜ Display hp as a percent in score
|
Display hp as a percent in score
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| SirRoughknight
(19 posts) Bio
|
| Date
| Mon 11 Jan 2010 06:27 PM (UTC) Amended on Mon 11 Jan 2010 06:39 PM (UTC) by SirRoughknight
|
| Message
| I'm using SmaugFUSS 1.9
Was wondering, I added in a new token from the prompts to display them as a "life" bar for the character pretty much from observing the C/c tokens.
case 'J':
if (ch->max_hit > 0)
percent = (100 * ch->hit ) / ch->max_hit;
else
percent = -1;
if (percent >= 100)
sprintf (pbuf, "&wLife[&R|||&Y||||&G|||&w]" );
else if (percent >= 90)
sprintf (pbuf, "&wLife[&R|||&Y||||&G||-&w]" );
else if (percent >= 80)
sprintf (pbuf, "&wLife[&R|||&Y||||&G|--&w]" );
else if (percent >= 70)
sprintf (pbuf, "&wLife[&R|||&Y||||&G---&w]" );
else if (percent >= 60)
sprintf (pbuf, "&wLife[&R|||&Y|||-&G---&w]" );
else if (percent >= 50)
sprintf (pbuf, "&wLife[&R|||&Y||--&G---&w]" );
else if (percent >= 40)
sprintf (pbuf, "&wLife[&R|||&Y|---&G---&w]" );
else if (percent >= 30)
sprintf (pbuf, "&wLife[&R|||&Y----&G---&w]" );
else if (percent >= 20)
sprintf (pbuf, "&wLife[&R||-&Y----&G---&w]" );
else if (percent >= 10)
sprintf (pbuf, "&wLife[&R|--&Y----&G---&w]" );
else
sprintf (pbuf, "&wLife[&R-&r-&R-&r-&R-&r-&R-&r-&R-&r-&w]" );
break;
The next step I wanted to take was displaying the character's hitpoints as "Life: ???% of 100%", in the score command but I must admit I'm a little lost.
Any help would be greatly appreciated in advance. | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #1 on Mon 11 Jan 2010 11:03 PM (UTC) |
| Message
| | Just take that formula you used for the int percent you have there and put it in score. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| SirRoughknight
(19 posts) Bio
|
| Date
| Reply #2 on Tue 12 Jan 2010 12:43 AM (UTC) Amended on Tue 12 Jan 2010 12:53 AM (UTC) by SirRoughknight
|
| Message
| I changed the following:
void do_score( CHAR_DATA* ch, const char* argument )
{
char buf[MAX_STRING_LENGTH];
char buf2[MAX_STRING_LENGTH];
char buf3[MAX_STRING_LENGTH];
char buf4[MAX_STRING_LENGTH];
AFFECT_DATA *paf;
int iLang;
int percent;//added int percent;
And added in:
if (ch->max_hit > 0)
percent = (100 * ch->hit ) / ch->max_hit;
else
percent = -1;
snprintf( buf, "%3.3d%", percent ); //line 265
pager_printf(ch, "Life: %s Gold: %-13s Save: %s\r",
buf, num_punct( ch->gold ),
ch->save_time ? ctime( &( ch->save_time ) ) : "None this session.\n" );
Compiled with the following errors:
Compiling o/player.o....
cc1plus: warnings being treated as errors
player.c: In function 'void do_score(CHAR_DATA*, const char*)':
player.c:265: warning: ' ' flag used with '%o' printf format
player.c:265: warning: too few arguments for format
make[1]: *** [o/player.o] Error 1
make: *** [all] Error 2
| | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #3 on Tue 12 Jan 2010 12:52 AM (UTC) |
| Message
|
SirRoughknight said:
player.c: In function 'void do_score(CHAR_DATA*, const char*)':
player.c:265: warning: ' ' flag used with '%o' printf format
player.c:265: warning: too few arguments for format
Those warnings brought me to look at printf-like calls. It sounded like you have a blank format wildcard, because it's expecting more parameters than you passed. Sure enough:
snprintf( buf, "%3.3d%", percent );
Change that to:
snprintf( buf, "%3.3d%%", percent );
A %% in printf() outputs one %. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| SirRoughknight
(19 posts) Bio
|
| Date
| Reply #4 on Tue 12 Jan 2010 12:58 AM (UTC) |
| Message
| Changed it to %3.3d%%
Did a make clean, tried to compile again.
Got the same errors as before. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,169 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Tue 12 Jan 2010 01:35 AM (UTC) |
| Message
| See "man snprintf":
SYNOPSIS
#include <stdio.h>
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
The second argument should be a size. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| SirRoughknight
(19 posts) Bio
|
| Date
| Reply #6 on Tue 12 Jan 2010 03:11 AM (UTC) Amended on Tue 12 Jan 2010 03:39 AM (UTC) by SirRoughknight
|
| Message
|
if (ch->max_hit > 0)
percent = (100 * ch->hit ) / ch->max_hit;
else
percent = -1;
snprintf( buf, MAX_STRING_LENGTH, "%-3d", percent );
pager_printf(ch, "Life: %s of 100 Gold: %-13s Save: %s\r",
buf, num_punct( ch->gold ),
ch->save_time ? ctime( &( ch->save_time ) ) : "None this session.\n" );
Displays perfectly how I wanted it.
Thank you very much Twisol, Zeno, and Nick. Ya'll are Aces. | | 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.
26,531 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top