maxman
Well-known member
Having the numeral 1 display on screen as a last active life number for players, has always been a standard, since the old BOR days. But what if I tell you that it's possible to display number 0 as player's last active life number without messing the sprites and/or code up mistakenly? How do you display it as a result? There are two ways to do it, but before jumping to it, let's start from the very beginning.
First off, let's take a close look at the positions of the life numbers from players. Each life number from a player is default in its own coordinates respectively. There's the easiest way to change coordinates anywhere around the screen.

To change the position of the life number from a specified player, add p{#}lifen in levels.txt, but do not use {#} symbol because the engine does not read or understand it. [#} represents a specified player number for it, so use a number instead of the symbol {#}. For example, add p1lifen for player 1 and p2lifen for player 2 in levels.txt. Change its coordinates.
Example:
You can save it in levels.txt and test the game if you like, but it's optional. It's just to show a sample of where the current life numbers are.

With this example given above, this results player 1's life number to be at the very top-left corner of the screen because its coordinate is all zeroes on screen. Its position of coordinates is easy to recognize on how the basic concept of OpenBOR as its beginning point of each sprite. For player 2's life number, however, it's moved 19 pixels down below from its default coordinates, since player 2's default position is or was 312, 2 (x, y) from the screen. OpenBOR reads pixels. If you are confused on where the exact position of a font (of a number) is located, examine/observe the number closely and measure it by pixels, given from a sample of p{#}lifen in levels.txt earlier.

For reference on how p{#}lifen is used, read this.
Now that you know how and where to place the players' own life numbers, it's time to show how to display number zero as a result.
Copy this script and save it as player_draw.c into your scripts folder.
player_draw.c:
After saving it, open a .txt file from any playable character and declare the script with ondrawscript. Save it after declaring ondrawscript to player_draw.c.
Example:
In short: About this script, it's a life number that is deducted by 1, which results as a new current life number for each player respectively.
Now that it's set, you will have a new current life number while p{#}lifen number still shows on screen. Your new life number is not going to replace and force p{#}lifen to change position values at all. But it's going to be drawn to the screen by displaying itself as a new number, as player's current life number being subtracted by 1. To hide p{#}lifen off screen, change its position value with any negative value (example below). It depends on the font size you have in the sprites folder, specifically its height size from a font. You can place your new current life number like you do/did with p{#}lifen by editing coordinates and/or font number inside your player_draw.c file, and you're done.
For coordinate and font references, read drawstring.
And here's your result.

Copy this script and paste it in update.c in the scripts folder, if your update.c is completely blank. Save it after you're done.
update.c:
There is no need to use and declare player's life number in ondrawscript since the engine can update it for you with player's custom life number in it. But that doesn't mean you cannot use it. You can use ondrawscript for anything else for your character.
First off, let's take a close look at the positions of the life numbers from players. Each life number from a player is default in its own coordinates respectively. There's the easiest way to change coordinates anywhere around the screen.

To change the position of the life number from a specified player, add p{#}lifen in levels.txt, but do not use {#} symbol because the engine does not read or understand it. [#} represents a specified player number for it, so use a number instead of the symbol {#}. For example, add p1lifen for player 1 and p2lifen for player 2 in levels.txt. Change its coordinates.
Example:
Code:
p1lifen 0 0 #131 2
p2lifen 312 21 #312 2
p1smenu 40 252 999 999
p2smenu 440 252 999 999
set Arcade
lives 1
nosame 1
scene data/scenes/target/tar1.txt
z 170 264 150
file data/levels/miami1.txt
You can save it in levels.txt and test the game if you like, but it's optional. It's just to show a sample of where the current life numbers are.

With this example given above, this results player 1's life number to be at the very top-left corner of the screen because its coordinate is all zeroes on screen. Its position of coordinates is easy to recognize on how the basic concept of OpenBOR as its beginning point of each sprite. For player 2's life number, however, it's moved 19 pixels down below from its default coordinates, since player 2's default position is or was 312, 2 (x, y) from the screen. OpenBOR reads pixels. If you are confused on where the exact position of a font (of a number) is located, examine/observe the number closely and measure it by pixels, given from a sample of p{#}lifen in levels.txt earlier.

For reference on how p{#}lifen is used, read this.
p{#}lifen {x} {y} {font}
- Determines the position of player 1's current number of lives. In case you haven't figured it out, the number on the right of lifebar is player's lives.
- {#} determines which player this setting is for and its possible values are 1, 2, 3 and 4. There's no space around {#} though.
- {x} and {y} are the number of pixels, right and down respectively, from the top left corner of the screen to the top left corner of the number.
- {font} determines which font is used for the number.
- Font reference is the same as 'p{#}lifex' above.
- Default value is 3 or font4.gif.
Now that you know how and where to place the players' own life numbers, it's time to show how to display number zero as a result.
Method #1: Using ondrawscript
Copy this script and save it as player_draw.c into your scripts folder.
player_draw.c:
C:
void main()
{
LifeNumber();
}
void LifeNumber()
{
// Current player life number display
int P1 = getplayerproperty(0, "entity"); // Player 1 entity
int P2 = getplayerproperty(1, "entity"); // Player 2 entity
int P1Life = getplayerproperty(0, "lives"); // Player 1's current life number
int P2Life = getplayerproperty(1, "lives"); // Player 2's current life number
if(P1){ // Player 1 exists?
drawstring(64, 8, 1, P1Life-1); // current player 1 life number to display life number result?
}
if(P2){ // Player 2 exists?
drawstring(289, 8, 1, P2Life-1); // current player 2 life number to display life number result?
}
}
After saving it, open a .txt file from any playable character and declare the script with ondrawscript. Save it after declaring ondrawscript to player_draw.c.
Example:
Code:
name Terry
type player
health 100
speed 10
gfxshadow 1
atchain 1
ondrawscript data/scripts/player_draw.c
In short: About this script, it's a life number that is deducted by 1, which results as a new current life number for each player respectively.
Now that it's set, you will have a new current life number while p{#}lifen number still shows on screen. Your new life number is not going to replace and force p{#}lifen to change position values at all. But it's going to be drawn to the screen by displaying itself as a new number, as player's current life number being subtracted by 1. To hide p{#}lifen off screen, change its position value with any negative value (example below). It depends on the font size you have in the sprites folder, specifically its height size from a font. You can place your new current life number like you do/did with p{#}lifen by editing coordinates and/or font number inside your player_draw.c file, and you're done.
Code:
p1lifen 0 -29
p2lifen 312 -21
p1smenu 40 252 999 999
p2smenu 440 252 999 999
set Arcade
lives 1
#credits 5
nosame 1
scene data/scenes/target/tar1.txt
z 170 264 150
file data/levels/miami1.txt
For coordinate and font references, read drawstring.
drawstring(int x, int y, int font#, text, layer)
- Draw the text in (x, y) of the screen, with font specified.
- This method is costy, because each character is a sprite. And to prevent blinking, have to put this function in an update script (a script that runs each game loop).
- layer is the z position
And here's your result.

Method #2: Using update.c or updated.c
Copy this script and paste it in update.c in the scripts folder, if your update.c is completely blank. Save it after you're done.
update.c:
C:
void main(){
LifeNumber();
}
void LifeNumber()
{
if(openborvariant("in_level"))
{
int P1 = getplayerproperty(0, "entity");
int P2 = getplayerproperty(1, "entity");
int P1Life = getplayerproperty(0, "lives");
int P2Life = getplayerproperty(1, "lives");
if(P1)
{
drawstring(131, 2, 3, P1Life-1);
}
if(P2)
{
drawstring(311, 2, 3, P2Life-1);
}
}
}
There is no need to use and declare player's life number in ondrawscript since the engine can update it for you with player's custom life number in it. But that doesn't mean you cannot use it. You can use ondrawscript for anything else for your character.
Last edited: