SA-MP Forums Archive
HealthBar - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: HealthBar (/showthread.php?tid=264294)



HealthBar - LZLo - 25.06.2011

HEllo! I have a bug with the delagged HealthBar: it don't 'move'
the original one is moving

It's important, because it's under onplayerupdate

ORIGINAL ONE:
PHP код:
    new Float:Health;
    
GetPlayerHealth(playerid,Health);
    if(
Health >= 95)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[2]);
    }
    else if(
Health >= 90 && Health 95)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[3]);
    }
    else if(
Health >= 85 && Health 90)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[4]);
    }
    else if(
Health >= 80 && Health 85)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[5]);
    }
    else if(
Health >= 75 && Health 80)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[6]);
    }
    else if(
Health >= 70 && Health 75)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[8]);
    }
    else if(
Health >= 65 && Health 70)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[9]);
    }
    else if(
Health >= 60 && Health 65)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[10]);
    }
    else if(
Health >= 55 && Health 60)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[11]);
    }
    else if(
Health >= 50 && Health 55)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[12]);
    }
    else if(
Health >= 45 && Health 50)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[14]);
    }
    else if(
Health >= 40 && Health 45)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[15]);
    }
    else if(
Health >= 35 && Health 40)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[16]);
    }
    else if(
Health >= 30 && Health 35)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[17]);
    }
    else if(
Health >= 25 && Health 30)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[18]);
    }
    else
    {
        for(new 
i=0i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
    } 

DELAGGED ONE:
PHP код:
    new Float:Health;
    
GetPlayerHealth(playerid,Health);
    if(
Health >= 95)
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[2]);
    }
    
    switch(
Health)
    {
    case 
90..94:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[3]);
    }
    case 
85..89:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[4]);
    }
    case 
80..84:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[5]);
    }
    case 
75..79:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[1]);
        
TextDrawShowForPlayer(playerid,HealthBar[6]);
    }
    case 
70..74:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[8]);
    }
    case 
65..69:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[9]);
    }
    case 
60..64:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[10]);
    }
    case 
55..59:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[11]);
    }
    case 
50..54:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[7]);
        
TextDrawShowForPlayer(playerid,HealthBar[12]);
    }
    case 
45..49:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[14]);
    }
    case 
40..44:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[15]);
    }
    case 
35..39:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[16]);
    }
    case 
30..34:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[17]);
    }
    case 
25..29:
    {
        for(new 
i=1i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
        
TextDrawShowForPlayer(playerid,HealthBar[13]);
        
TextDrawShowForPlayer(playerid,HealthBar[18]);
    }
    case 
0..24:
    {
        for(new 
i=0i<19i++) TextDrawHideForPlayer(playerid,HealthBar[i]);
    }
    } 



AW: HealthBar - Nero_3D - 25.06.2011

you need to use floats in your switch

or you round the health to an integer

but actually how does this healthbar looks like, a row of symbols ?


Re: HealthBar - LZLo - 25.06.2011

please write a very short example, i have been working with it since morning


AW: HealthBar - Nero_3D - 25.06.2011

Here with floatround

pawn Код:
//
    new
        i = 1,
        Float: Health;
    for( ; i != 19; ++i) {
        TextDrawHideForPlayer(playerid, HealthBar[i]);
    }
    GetPlayerHealth(playerid, Health);
    switch(floatround(((Health / 5.0), floatround_floor)) {
        case 18: { //18 * 5 => 90 - 94
            TextDrawShowForPlayer(playerid,HealthBar[1]);
            TextDrawShowForPlayer(playerid,HealthBar[2]);
        }
        //...
        case 5: { //5 * 5 => 25 - 29
            TextDrawShowForPlayer(playerid,HealthBar[13]);
            TextDrawShowForPlayer(playerid,HealthBar[18]);
        }
        case 0..4: {} // 0 - 24
        default: { //everything which isnt between 0 - 94
            TextDrawShowForPlayer(playerid,HealthBar[1]);
            TextDrawShowForPlayer(playerid,HealthBar[2]);
        }
    }
Another note:

Using "85..89" doesnt speed up the code, its the same as "85, 86, 87, 89" (4 checks)

if(85 <= health < 90) would be better in that case

PS: Cant prove that at the moment, but I am quite sure that this is correct


Re: HealthBar - LZLo - 25.06.2011

thank you, i'll use it