07-22-2012, 11:40
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.
PS: When you have only three hearts, the bar is animated as in Minecraft.
___________________________________________________________________________________________________________________________________
Put this line in init()
If you are a beginner modder, place it in onPlayerSpawned() under self waittill("spawned_player");
Place this code where you want
Put these lines in mod.csv
And for finish, download images.zip, then unzip it into mp_yourmod and rebuild your mod.
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.