[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Health messages rather than HP

Health messages rather than HP

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


Posted by Valna   (15 posts)  [Biography] bio
Date Thu 25 Mar 2004 04:47 AM (UTC)
Message
ok i'm workin on a swr 1.0 downloaded from this site. Going for something slightly more realistic than the stock code. anyhow i'm putting in a health command and taking HP out of the score command. this is the code that i wrote for health:


void do_health(CHAR_DATA * ch, char *argument)
{
   char *hpt;
   int hitpct;
   int chmax = ch->max_hit;
   int chhit = ch->hit;

   hitpct = ((chmax / chhit) * 100);

   if (hitpct > 100 && hitpct != 100) { hpt = "envigorated";    }
   else if ((hitpct = 100) || hitpct >= 95) { hpt = "healthy";  }
   else if (hitpct < 95 && hitpct >= 90) { hpt = "scuffed";     }
   else if (hitpct < 90 && hitpct >= 80) { hpt = "bruised";     }
   else if (hitpct < 80 && hitpct >= 70) { hpt = "scratched";   }
   else if (hitpct < 70 && hitpct >= 60) { hpt = "injured";     }
   else if (hitpct < 60 && hitpct >= 50) { hpt = "beat up";     }
   else if (hitpct < 50 && hitpct >= 40) { hpt = "wounded";     }
   else if (hitpct < 40 && hitpct >= 30) { hpt = "mauled";      }
   else if (hitpct < 30 && hitpct >= 20) { hpt = "maimed";      }
   else if (hitpct < 20 && hitpct >= 10) { hpt = "in bad shape";        }
   else if (hitpct < 10 && hitpct >= 0) { hpt = "at death's door";      }
   else { hpt = "DEAD"; }

   ch_printf(ch, "You currently feel %s\n\r", hpt);
   return;
}


anyway i'm sure it's obvious to someone out there what i'm doing wrong, the command will function but it always returns a "healthy" result even when badly wounded. Any ideas?
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 25 Mar 2004 05:50 AM (UTC)

Amended on Thu 25 Mar 2004 05:52 AM (UTC) by Nick Gammon

Message
Well, for a start this line is rather bizarre:

if (hitpct > 100 && hitpct != 100) ...

You are saying that if hitpct is greater than 100 *and* is not 100. Surely if it is greater than 100, it will not *be* 100.

Anyway, I think you have the percentage the wrong way around. Let's say you have 40 1-cent coins in your pocket, the percentage of $1 is 40/100 not 100/40.

So I would start by changing this line:

hitpct = ((chmax / chhit) * 100);

to

hitpct = (chhit * 100) / chmax;

I would do the multiply before the divide, because otherwise you are likely to get integer arithmetic which would be:

40 hp / 100 hp = 0
Multiply by 100 still gives 0.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #2 on Thu 25 Mar 2004 06:17 AM (UTC)
Message
Theres also the option of
hitpct = ((chhit % chmax) * 100);
if you want to do division first.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Valna   (15 posts)  [Biography] bio
Date Reply #3 on Thu 25 Mar 2004 07:05 AM (UTC)
Message
I hadn't even thought about the fact that if it was greater than 100 it would obviously not be 100. I was just insuring that 100 would still be only healthy, but yeah that makes a lot of sense, i'll try the changes you recommended. Thanks Nick.
[Go to top] top

Posted by Valna   (15 posts)  [Biography] bio
Date Reply #4 on Thu 25 Mar 2004 08:17 AM (UTC)
Message
Ok i made the changes you suggested, but i'm still always returning a "healthy" response. i did a make clean and recompiled. set up the command with cedit and it was still calling reserved in commands.dat so i changed it there too. still nothing.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 25 Mar 2004 08:39 PM (UTC)
Message
Ah yes, here is your problem. This line:


else if ((hitpct = 100) || hitpct >= 95) { hpt = "healthy"; }


I know it is subtle if you are not looking closely but the first part (hitpct = 100) *sets* the hitpct to 100.

You mean:


else if ((hitpct == 100) || hitpct >= 95) { hpt = "healthy"; }


Because of that the hitpct will always be 100 and thus he will always be healthy.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Valna   (15 posts)  [Biography] bio
Date Reply #6 on Sat 27 Mar 2004 01:39 AM (UTC)
Message
Heh, thanks a lot nick, i'm still pretty new to this.. i've been reading up on C and working on this code as my practice but i'm still prone to mistakes such as that. thanks for pointing it out, works fine now.
[Go to top] 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.


16,474 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]