Battery -
No Fear - 29.12.2011
pawn Код:
if ( TVar[ playerid ][ tBattery ] <= 100 ) { format( Battery, sizeof( Battery ),"|||||");}
else if ( TVar[ playerid ][ tBattery ] <= 75 ) { format( Battery, sizeof( Battery ),"||||");}
else if ( TVar[ playerid ][ tBattery ] <= 50 ) { format( Battery, sizeof( Battery ),"|||" );}
else if ( TVar[ playerid ][ tBattery ] <= 25 ) { format( Battery, sizeof( Battery ),"||" );}
else if ( TVar[ playerid ][ tBattery ] <= 0 ) { format( Battery, sizeof( Battery ),"|" );}
whats wrong it's showing 5 bars, even if i have 0 battery
Re: Battery -
Seven_of_Nine - 29.12.2011
I'd just use it like Battery = "||||" etc.
Perhaps the battery script is wrong. Show us the part when you set the TVar!
Re: Battery -
No Fear - 29.12.2011
nah, it's working fine... i just checked, the problem is with this script... :/ maybe i'm using wrong " <= "
Re: Battery -
Seven_of_Nine - 29.12.2011
Quote:
Originally Posted by No Fear
nah, it's working fine... i just checked, the problem is with this script... :/ maybe i'm using wrong " <= "
|
Ooooh you do.
The first line says if TVar is less or equal with 100 then 5 bars. xD
Flip them around.
EDIT: Yes, like that.
Re: Battery -
No Fear - 29.12.2011
You mean this
TVar[ playerid ][ tBattery ] >= 100
Re: Battery -
[ABK]Antonio - 29.12.2011
Quote:
Originally Posted by No Fear
pawn Код:
if ( TVar[ playerid ][ tBattery ] <= 100 ) { format( Battery, sizeof( Battery ),"|||||");} else if ( TVar[ playerid ][ tBattery ] <= 75 ) { format( Battery, sizeof( Battery ),"||||");} else if ( TVar[ playerid ][ tBattery ] <= 50 ) { format( Battery, sizeof( Battery ),"|||" );} else if ( TVar[ playerid ][ tBattery ] <= 25 ) { format( Battery, sizeof( Battery ),"||" );} else if ( TVar[ playerid ][ tBattery ] <= 0 ) { format( Battery, sizeof( Battery ),"|" );}
whats wrong it's showing 5 bars, even if i have 0 battery
|
pawn Код:
switch(Tvar[playerid][tBattery])
{
case 100: format(Battery, sizeof(Battery),"|||||");
case 75..99: format(Battery, sizeof(Battery),"||||");
case 50..74: format(Battery, sizeof(Battery),"|||");
case 25..49: format(Battery, sizeof(Battery),"||");
case 0..24: format(Battery, sizeof(Battery),"|");
}
Could try that out
Re: Battery -
Seven_of_Nine - 29.12.2011
Quote:
Originally Posted by [ABK]Antonio
pawn Код:
switch(Tvar[playerid][tBattery]) { case 100: format(Battery, sizeof(Battery),"|||||"); case 75..99: format(Battery, sizeof(Battery),"||||"); case 50..74: format(Battery, sizeof(Battery),"|||"); case 25..49: format(Battery, sizeof(Battery),"||"); case 0..24: format(Battery, sizeof(Battery),"|"); }
Could try that out
|
Only this'd work. Give him a rep!
Re: Battery -
No Fear - 29.12.2011
Thanks, both, giving rep both
Re : Battery -
decondelite - 29.12.2011
This is more optimized and has a better repartition I think:
pawn Код:
if ( TVar[ playerid ][ tBattery ] > 80 ) { format( Battery, sizeof( Battery ),"|||||");}
else if ( TVar[ playerid ][ tBattery ] > 60 ) { format( Battery, sizeof( Battery ),"||||");}
else if ( TVar[ playerid ][ tBattery ] > 40 ) { format( Battery, sizeof( Battery ),"|||" );}
else if ( TVar[ playerid ][ tBattery ] > 20 ) { format( Battery, sizeof( Battery ),"||" );}
else { format( Battery, sizeof( Battery ),"|" );}
There's also another way to do:
pawn Код:
format( Battery, sizeof( Battery ),"|||||");
Battery[TVar[playerid][tBattery]/20]='\0';
I need this second solution to be confirmed though: I have no script to test it. I'll explain the principle: '\0' is the "end of string" character, which is used to determine where is the end of the string. When a script reads that character, it assumes that the previous character was the last one.