maxman
Well-known member
I have a lifebar script with flowing reduction set for players in ondrawscript. But my problem is that when I use entityvar, along with drawsprite, that is in conjunction with globalvar, I cannot run the game because I use drawsprite. What I want is to draw the sprite to the screen where the player's icon is. The reduced lifebar set in entityvars only works without using drawsprite in globalvars.
I'm using @msmalik681's HP Bar script as a reference for reducing HP bar while allowing the red bar to decrease flowingly. I'm trying to make the HP bar decrease flowingly like the red bar. It's like Street Fighter 2, Super Double Dragon, and some others that have those kind in the way the life bars are reduced.
Reference:
I get this crash for running drawsprite and entityvar in an update script (ondrawscript/update.c/updatescript). Maybe it's got to do with using drawsprite.
I see how the lifebar increases and decreases flowingly without the cut in @Kratus's Streets of Rage X game. I edited @msmalik681's HP bar for the actual health bar and the result turns out very nice. But upon adding (load/draw)sprite into the code, I have problem.
How can I have a sprite for a specific player drawn on screen along with entityvars set without a problem?
My last question is this: Can't entityvars be used in update.c?
C:
void main(){
playerHealth();
}
void playerHealth(){
void self = getlocalvar("self");
// PLAYER SIDE
int P1 = getplayerproperty(0, "entity");
int P2 = getplayerproperty(1, "entity");
void P1Name = getentityproperty(P1, "defaultname");
void P2Name = getentityproperty(P2, "defaultname");
int P1HP = getentityproperty(P1, "health");
int P2HP = getentityproperty(P2, "health");
int P1MaxHP = getentityproperty(P1, "maxhealth");
int P2MaxHP = getentityproperty(P2, "maxhealth");
int P1Health = 93*P1HP/P1MaxHP;
int P2Health = 93*P2HP/P2MaxHP;
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);}
void Bar = getglobalvar("Bar");
if(P1 != NULL()){
drawbox(26,9,getentityvar(self, "playerOne"),10,999,rgbcolor(56,160,248),0);
drawsprite(Bar, 1, 8, 2500);
}
if(P2 != NULL()){
drawbox(156,9,getentityvar(self, "playerTwo"),10,999,rgbcolor(56,160,248),0);
drawsprite(Bar, 131, 8, 2500);
}
if(P1Health < getentityvar(self, "playerOne")){
if(getentityvar(self,1)==NULL()){
setentityvar(self,1,0);
}
setentityvar(self,1,getentityvar(self,1)+1);
if(getentityvar(self,1) > 7){
setentityvar(self, "playerOne",getentityvar(self, "playerOne")-1);
setentityvar(self,1,0);
}
}
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);
}
}
}
void oncreate(){
void Bar;
if(!Bar){
Bar = loadsprite("data/sprites/bar.gif");
setglobalvar("Bar", Bar);
}
}
void ondestroy(){
void Bar = getglobalvar("Bar");
if(Bar){
free(Bar);
setglobalvar("Bar", NULL());
}
}
I'm using @msmalik681's HP Bar script as a reference for reducing HP bar while allowing the red bar to decrease flowingly. I'm trying to make the HP bar decrease flowingly like the red bar. It's like Street Fighter 2, Super Double Dragon, and some others that have those kind in the way the life bars are reduced.
Reference:
C:
void main()
{
if(getplayerproperty(0, "entity") == NULL() && getplayerproperty(1, "entity") == NULL()){
}else{
void self = getlocalvar("self"); //get calling entity
float x = getentityproperty(self, "x") - openborvariant("xpos") - 25; //get caller x value minus 25
float z = getentityproperty(self, "z"); //get caller z value
float a = getentityproperty(self, "a"); //get caller a value
float y = z - a - openborvariant("ypos") - getentityproperty(self, "maxmp"); // get caller y position and move it up by entity max mp value
int maxhp = getentityproperty(self,"maxhealth"); // get caller max hp
int hp = getentityproperty(self,"health"); // get caller current hp
int health = hp / 0.01 / maxhp / 2; // work out current hp percentage and half it
if(getentityvar(self,0)==NULL()){setentityvar(self,0, health);} //set enity var to 0 if no value (null)
drawbox(x,y,health,5,z+2,rgbcolor(223,214,73),0); //draw hp box using x and y cords also z value is +2 so its on top of other 2 boxes
drawbox(x,y,getentityvar(self,0),5,z+1,rgbcolor(181,26,0),0); //second box to show damage with a z+1 value so its under hp bar and entity var 0 controls its size
drawbox(x,y,50,5,z,0,0); //black box in background to show how much original life bar was
if(health<getentityvar(self,0)) // 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 tic
if(getentityvar(self,1) > 50) //if timer over 50
{
setentityvar(self,0,getentityvar(self,0)-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
}
}
}
}
I get this crash for running drawsprite and entityvar in an update script (ondrawscript/update.c/updatescript). Maybe it's got to do with using drawsprite.
Code:
Function requires a valid sprite handle 3 integer values, 5th integer value is optional: drawsprite(sprite, int x, int y, int z, int sortid)
Script function 'drawsprite' returned an exception, check the manual for details.
parameters: <VT_EMPTY> Unitialized, 30, 218, 2500,
I see how the lifebar increases and decreases flowingly without the cut in @Kratus's Streets of Rage X game. I edited @msmalik681's HP bar for the actual health bar and the result turns out very nice. But upon adding (load/draw)sprite into the code, I have problem.
How can I have a sprite for a specific player drawn on screen along with entityvars set without a problem?
My last question is this: Can't entityvars be used in update.c?