ItsMods

Full Version: Animated Health Bar from Minecraft
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I created this health bar for my Minecraft mod, but i never finished him, so i prefer share the code that keep it for myself.

[Image: 3890AC754F32C9D214876684DC8C1554E10FFF4F]


PS: When you have only three hearts, the bar is animated as in Minecraft.
___________________________________________________________________________________________________________________________________

Put this line in init()
Code:
level thread precacheAll()

If you are a beginner modder, place it in onPlayerSpawned() under self waittill("spawned_player");
Code:
self.health = 100;
self.maxhealth = self.health;
self thread Health();

Place this code where you want
Code:
precacheAll()
{
    // Shaders
    precacheShader("health10");
    precacheShader("health9");
    precacheShader("health8");
    precacheShader("health7");
    precacheShader("health6");
    precacheShader("health5");
    precacheShader("health4");
    precacheShader("health3");
    precacheShader("health2_1");
    precacheShader("health2_2");
    precacheShader("health2_3");
    precacheShader("health1_1");
    precacheShader("health1_2");
    precacheShader("health1_3");
    precacheShader("health1_3");
}

Health()
{
    self endon("death");
    self endon("disconnect");

        Health = createIcon( "health10", 192, 48 );
        Health setPoint( "CENTER", "BOTTOM", 0, -20 );
        self thread Destroy( Health );

    for(;;)
    {
        if(self.health <= 100 && self.health >= 95)
        {
            Health setShader( "health10", 192, 48 );
        }

        else if(self.health < 95 && self.health >= 85)
        {
            Health setShader( "health9", 192, 48 );
        }

        else if(self.health < 85 && self.health >= 75)
        {
            Health setShader( "health8", 192, 48 );
        }

        else if(self.health < 75 && self.health >= 65)
        {
            Health setShader( "health7", 192, 48 );
        }

        else if(self.health < 65 && self.health >= 55)
        {
            Health setShader( "health6", 192, 48 );
        }

        else if(self.health < 55 && self.health >= 45)
        {
            Health setShader( "health5", 192, 48 );
        }

        else if(self.health < 45 && self.health >= 35)
        {
            Health setShader( "health4", 192, 48 );
        }

        else if(self.health < 35 && self.health >= 25)
        {
            Health setShader( "health3", 192, 48 );
        }

        else if(self.health < 25 && self.health >= 15)
        {
            Health setShader( "health2_1", 192, 48 );
            wait 0.1;
            Health setShader( "health2_2", 192, 48 );
            wait 0.1;
            Health setShader( "health2_3", 192, 48 );
            wait 0.1;
        }

        else if(self.health < 15 && self.health >= 1)
        {
            Health setShader( "health1_1", 192, 48 );
            wait 0.1;
            Health setShader( "health1_2", 192, 48 );
            wait 0.1;
            Health setShader( "health1_3", 192, 48 );
            wait 0.1;
        }

    wait .1;
    }
}

Destroy( hudElem )
{
    self waittill ( "death" );
    hudElem destroy();
}

Put these lines in mod.csv
Code:
material,health1_1
material,health1_2
material,health1_3
material,health2_1
material,health2_2
material,health2_3
material,health3
material,health4
material,health5
material,health6
material,health7
material,health8
material,health9
material,health10

And for finish, download images.zip, then unzip it into mp_yourmod and rebuild your mod.
cool, but takes many materials Sad
(For Black Ops obv)
(07-22-2012, 17:24)JayDi Wrote: [ -> ]cool, but takes many materials Sad
(For Black Ops obv)

Yes, but i'm noob modder, so i have many files, but the code is very simple. Tongue