Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!, Bing, DotBot

Members: 0
Guests: 20
Stats
Files
Topics
Posts
Members
Newest Member
476
3,704
19,231
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWR FUSS » Could use an assist
Forum Rules | Mark all | Recent Posts

Could use an assist
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Sep 26, 2009, 9:19 am   Last edited Sep 26, 2009, 9:24 am by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

I'm trying to set things up for blasters so, if the players have a certain flag set using the config command, they'll see a color coded string of |'s denoting how much charge is left in their blasters, based on a percentage, as apposed to the standard of just showing how much is left numerically. If they have a full charge the bars all show up bright green as they're supposed to, but once they start fighting all the bars are bright red, which should only happen if that particular weapon is out of ammo.
Here's what I did.
if( !ch->pcdata->flags.test( PLR_METER ) )
   ch_printf( ch, " &R[&Y%d&r]&w ", obj->value[4] );
else
   ch_printf( ch, " &r[%s&r]&w ", ( ( obj->value[4] / obj->value[5] ) * 100 ) == 100 ? "&G||||||||||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 90 ?  "&G|||||||||&Y|"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 80 ?  "&G||||||||&Y|&R|"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 70 ?  "&G|||||||&Y|&R||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 60 ?  "&G||||||&Y|&R|||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 50 ?  "&G|||||&Y|&R||||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 40 ?  "&G||||&Y|&R|||||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 30 ?  "&G|||&Y|&R||||||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 20 ?  "&G||&Y|&R|||||||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) >= 10 ?  "&G|&Y|&R||||||||"
                                : ( ( obj->value[4] / obj->value[5] ) * 100 ) > 0 ?    "&Y|&R|||||||||"
                                :  "&R||||||||||"
                                );

Testing a blaster with a v4 of 1826 and v5 of 2000, I got 91.3, which is higher than 90, but it won't send the appropriate string of "&G|||||||||&Y|".

This would, ideally show up something like this:
|||||||||| at 100
|||||||||| at 90+
|||||||||| at 80+
and so on.
       
Post is unread #2 Sep 26, 2009, 10:29 am
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,857
JoinedJul 26, 2005

Well the way you have it is translating to this

0 (Is 0.913) * 100 which is still going to end up being 0 for you.

Try putting it like this

( ( 100 * obj->value[4] ) / obj->value[5] )

One of the best ways to do it is drop the numbers to lower ones and then do the % calculation.

That should give it to you the way you want. Now if however you end up with high obj->value[4] multiplying it by 100 can make it bad, but for the most part it should work right lol.
       
Post is unread #3 Sep 26, 2009, 11:10 am
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

Thanks much!

You'd think that if a calculator could come up with the correct answer a high level programming language like C/C++ could as well. :mad:

Generally speaking, 2000 should be the highest both values will be, and that's only if they're set to that manually. If value[5] isn't set when the item is created then it gets set automatically during item creation to something around 1000 and value[4] gets set to whatever that ends up as.
       
Post is unread #4 Sep 26, 2009, 1:36 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

It has to do with integer vs. floating point division. Integer division won't give you floating point numbers, so 3/2 == 1. But 3/2.0 == 1.5, 3.0/2 == 1.5, etc.

Remcon's reordering of the expression doesn't change the fact that it's integer division, but it means that integer division suffices for your purposes.
       
Pages:<< prev 1 next >>