Battery
#1

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
Reply
#2

I'd just use it like Battery = "||||" etc.
Perhaps the battery script is wrong. Show us the part when you set the TVar!
Reply
#3

nah, it's working fine... i just checked, the problem is with this script... :/ maybe i'm using wrong " <= "
Reply
#4

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.
Reply
#5

You mean this

TVar[ playerid ][ tBattery ] >= 100
Reply
#6

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
Reply
#7

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!
Reply
#8

Thanks, both, giving rep both
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)