void health() // Player health
{//Update script with player lifebar
//Calling main player
void self = getlocalvar("self");
int P1 = getplayerproperty(0, "entity");
int P2 = getplayerproperty(1, "entity");
void P1Name = getentityproperty(P1, "name");
void P2Name = getentityproperty(P2, "name");
int P1HP = getentityproperty(P1, "health");
int P2HP = getentityproperty(P2, "health");
int P1MaxHP = getentityproperty(P1, "maxhealth");
int P2MaxHP = getentityproperty(P2, "maxhealth");
int P1Health = 114*P1HP/P1MaxHP;
int P2Health = 114*P2HP/P2MaxHP;
int P1MP = getentityproperty(P1, "mp");
int P2MP = getentityproperty(P2, "mp");
int P1MaxMP = getentityproperty(P1, "maxmp");
int P2MaxMP = getentityproperty(P2, "maxmp");
int P1Mana = 70*P1MP/P1MaxMP;
int P2Mana = 70*P2MP/P2MaxMP;
int P1Score = getplayerproperty(0, "score");
int P2Score = getplayerproperty(1, "score");
int hres = openborvariant("hresolution");
void Branch = openborvariant("current_branch");
void T1 = findtarget(P1);
void T2 = findtarget(P2);
int THP1 = getentityproperty(T1, "health");
int THP2 = getentityproperty(T2, "health");
if(getentityvar(self, "playerOne") == NULL()){setentityvar(self, "playerOne", P1Health);} // SET FOR PLAYER'S HEALTH BAR SMOOTH REDUCTION INDEPENDENTLY
if(getentityvar(self, "playerTwo") == NULL()){setentityvar(self, "playerTwo", P2Health);}
if(getglobalvar("hpBar1") == NULL()){
setglobalvar("hpBar1", loadsprite("data/sprites/hud.png"));
}
void hpBar1 = getglobalvar("hpBar1");
if(!hpBar1){
hpBar1 = loadsprite("data/sprites/hud.gif");
setglobalvar("hpBar1", hpBar1);
}
if(P1 != NULL() && Branch != "Strength_Training"){
drawbox((150-P1Health),6,P1Health,2,1800,rgbcolor(255,234,41),0);
drawbox((150-P1Health),8,P1Health,1,1800,rgbcolor(255,226,0),0);
drawbox((150-P1Health),9,P1Health,1,1800,rgbcolor(255,206,24),0);
drawbox((150-P1Health),10,P1Health,1,1800,rgbcolor(246,194,0),0);
drawbox((150-P1Health),11,P1Health,1,1800,rgbcolor(230,141,0),0);
drawbox((150-P1Health),12,P1Health,1,1800,rgbcolor(222,92,0),0);
drawbox((150-getentityvar(self, "playerOne")),6,getentityvar(self, "playerOne"),7,1700,rgbcolor(181,26,0),0);
drawstring(33, 55, 1, P1Name);
drawstring(66, 43, 1, P1Score);
changeentityproperty(P1, "iconposition", -56, 21);
}if(P2 != NULL() && Branch != "Strength_Training"){
drawbox(176,6,P2Health,2,1800,rgbcolor(255,234,41),0);
drawbox(176,8,P2Health,1,1800,rgbcolor(255,226,0),0);
drawbox(176,9,P2Health,1,1800,rgbcolor(255,206,24),0);
drawbox(176,10,P2Health,1,1800,rgbcolor(246,194,0),0);
drawbox(176,11,P2Health,1,1800,rgbcolor(230,141,0),0);
drawbox(176,12,P2Health,1,1800,rgbcolor(222,92,0),0);
drawbox(176,6,getentityvar(self, "playerTwo"),7,1700,rgbcolor(181,26,0),0);
drawstring(hres-27-strwidth(P2Name, 0), 55, 0, P2Name);
drawstring(175, 43, 0, P2Score);
}
if(Branch == "Strength_Training"){
if(P1 != NULL()){
drawstring(33, 55, 1, P1Name);
drawstring(66, 43, 1, P1Score);
changeentityproperty(P1, "iconposition", -56, -41);
drawbox((150-P1Health),-106,P1Health,2,1800,rgbcolor(255,234,41),0);
drawbox((150-P1Health),-108,P1Health,1,1800,rgbcolor(255,226,0),0);
drawbox((150-P1Health),-109,P1Health,1,1800,rgbcolor(255,206,24),0);
drawbox((150-P1Health),-110,P1Health,1,1800,rgbcolor(246,194,0),0);
drawbox((150-P1Health),-111,P1Health,1,1800,rgbcolor(230,141,0),0);
drawbox((150-P1Health),-112,P1Health,1,1800,rgbcolor(222,92,0),0);
drawbox((150-getentityvar(self,0)),-106,getentityvar(self,0),7,1700,rgbcolor(181,26,0),0);
}
if(P2 != NULL()){
drawbox(176,-106,P2Health,2,1800,rgbcolor(255,234,41),0);
drawbox(176,-108,P2Health,1,1800,rgbcolor(255,226,0),0);
drawbox(176,-109,P2Health,1,1800,rgbcolor(255,206,24),0);
drawbox(176,-110,P2Health,1,1800,rgbcolor(246,194,0),0);
drawbox(176,-111,P2Health,1,1800,rgbcolor(230,141,0),0);
drawbox(176,-112,P2Health,1,1800,rgbcolor(222,92,0),0);
drawbox(176,-106,getentityvar(self,0),6,1700,rgbcolor(181,26,0),-1);
changeentityproperty(P2, "iconposition", 262, -41);
drawstring(hres-27-strwidth(P2Name, 0), 55, 0, P2Name); // drawstring(x,y,font,text,z);
drawstring(175, 43, 0, P2Score);
}
}
if(P1Health < getentityvar(self, "playerOne")){ // if hp box smaller then damage box
if(getentityvar(self,1)==NULL()){
setentityvar(self,1,0); //set entity var 1 to zero if null this is a timer
}
setentityvar(self,1,getentityvar(self,1)+1); //add 1 to timer this will run every game tick
if(getentityvar(self,1) > 7){ //if timer over 7
setentityvar(self, "playerOne",getentityvar(self, "playerOne")-1); //reduce displayed damage by 1
setentityvar(self,1,0); //reset timer to zero this will cause a loop untill damage is the same as hp
}
}
if(P2Health < getentityvar(self, "playerTwo")){
if(getentityvar(self,1)==NULL()){
setentityvar(self,1,0);
}
setentityvar(self,1,getentityvar(self,1)+1);
if(getentityvar(self,1) > 7){
setentityvar(self, "playerTwo",getentityvar(self, "playerTwo")-1);
setentityvar(self,1,0);
}
}
}