im making a text mud and having trouble working woth percents, i got a couple questions.
1) when a user uses a teleport item i want a certain percentage of their experience to be used, i have tried 3 different ways and it always takes all of it or only works if working with a maxz value of 100.
example:
int pcnt = 10;
if((cptr->exp)&&(pcnt))
{
cptr->exp-=(cptr->exp * (FLOAT)pcnt);
}
this always comes back as negative.
can anyone point me the best way to turn the var pcnt into the actual percentage of cptr->exp?
2) each user stat gives a percentage bonus of stat/5, is this the best way to do this:
You seem to misunderstand how %s work. All the numbers you have there are in decimal form, so 10 would be equal to 1000%, not 10%.
I've never understood why people keep writing MUDs in C and they don't upgrade to C++...anyway...
1.) You would need to get the correct percentage (probably a constant you define somewhere), then multiply it by their cur exp to get the amount they need to lose. Then subtract that from their cur exp and take either that number or 0, whichever is higher (unless you don't care if they have negative experience)
2.) If you want integer division, you can do it that way. Otherwise I would instead make 5 a float so can get stuff like 3 Str >> .75% damage bonus.
1) the constant is in the configuration file called portpcnt and is a value from 0-100
0 meaning they lose nothing and 100 meaning they lose it all.
so lets call this INT pcnt;
so i multiply this by their current exp like lose=(pcnt * cptr->experience)?
to counter negative exp i do a if(lose>0) cptr->exp-=lose;
could you throw me a small example?
2) so this method is not doing what i want? i know for dwarves i give everyone a 1% damage bonus as a passive skill thats simply done as
if(cptr->race==DWARF)
{
dmg+=(dmg * .01);
}
what way would you reccomend going about this for the strength bonus?
im using this game engine to teach myself more advanced stuff as i go along.
the game engine is actually done and been online for 3 weeks with only 3 small crashes which were quickly fixed .... (never use unsigned integers when negative damage is bad!)
as far as the language, im currently using borland c++ 5.01 because the game is actually a plug in to worldgroup bbs software for NT.
i found this site through a search cause im a quick learner when getting positive critisizm, the replies like 'noob, learn to code, blah blah" almost had me wanting to quit til a friend who is a former c++ game developer now doing sql web games said this was a great site.
i plan on doing a small engine using SQL databasing which is working good now but the new API is gonna require c++ 5.5 so ill be moving to that later on.