Welcome, Guest. Please login or register.

What openbor you prefer: Double dragon,battletoads or final fight !? by lirexpatrio
[December 07, 2012, 07:15:27 pm]


what are your favorite games OpenBOR?! by lirexpatrio
[December 07, 2012, 07:09:46 pm]


Post Some Awesome Videos by maxman
[December 07, 2012, 05:51:39 pm]


Can @cmd playmusic "aaaa" 1 also increse music sound ? by BeasTie
[December 07, 2012, 05:24:38 pm]


Streets of Rage: Silent Storm by mtrain
[December 07, 2012, 03:45:05 pm]


Site will be down for maintenance on 12/8/2012 thru 12/10/2012 by Damon Caskey
[December 07, 2012, 07:42:42 am]


Cancelled SOR 3d Remake by riccochet
[December 07, 2012, 03:58:33 am]


Dungeon Fighter: B.O.R. by msmalik681
[December 07, 2012, 03:24:27 am]


[TUTORIAL] How to create 4 Games of OpenBOR in 1 CD (650 MB) by magggas
[December 06, 2012, 09:46:25 pm]


custknife by Bloodbane
[December 06, 2012, 09:34:09 pm]


blockfx help by B.Kardi
[December 06, 2012, 04:09:14 pm]


street of age 4 hd by corradlo
[December 06, 2012, 01:41:36 pm]


ClaFan - Classic Fantasy ver 1.17 by soniczxblade
[December 06, 2012, 05:01:20 am]


Bug Archive by Bloodbane
[December 06, 2012, 02:00:44 am]


"Bio-Doom" and "Gears of Doom" by BulletBob
[December 05, 2012, 10:07:21 pm]


Contra Locked 'N' Loaded v2 by Bloodbane
[December 05, 2012, 09:39:43 pm]


Downloadable OpenBoR Manual by BeasTie
[December 05, 2012, 08:31:24 pm]


Having trouble testing changes by B.Kardi
[December 05, 2012, 03:05:53 pm]


DragonBall Absalon by msmalik681
[December 05, 2012, 02:52:13 pm]


[Hi-Res] Swamp by Vibrant
[December 05, 2012, 10:47:14 am]


  • Dot Guests: 117
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.



Author Topic: Draw player health to screen with fonts/numbers  (Read 3123 times)

0 Members and 1 Guest are viewing this topic.

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Draw player health to screen with fonts/numbers
« on: December 09, 2011, 12:25:00 am »
I know I mentioned trying this before but I think it's my best bet as a starting to point to learn some script.  So I thought I'd start a new thread and work towards getting something to work.

I can get code to work to display the numbers to screen, the problem I'm having is retrieving the player's health and getting it to display it.  I thought even thou probably crude I could at least store the players health and just setup a drawstring for every amount 0-100, to test I was trying to just display 0 or 100.

I've made a few attempts but this is basically along the lines of what I've tried, I know this is wrong and too simple right now but it's just to outline how I want it to work.

Code: [Select]
void main()
{
    void self = getlocalvar("self"); //Get calling entity.
    void Health = getentityproperty(self,"health");
    if(health==0);
    {
        drawstring(50, 75, 3, "0");
    }
    else if(health==100);
    {
        drawstring(50, 75, 3, "100");
    }
}

then repeated for each number, or even better just get player health and drawstring displays whatever value it has, when we did it done in the source code you could just do something like this

drawstring(50, 75, 3, %Health);

I also tried to do it with 'settextobj' methods but failed.

What should I be doing to get the player's health and store it properly?

Offline MatMan

  • Hero Member
  • *****
  • Posts: 1320
Re: Draw player health to screen with fonts/numbers
« Reply #1 on: December 09, 2011, 12:48:31 am »
Don't ever use Drawstring, use settextobj which is much resource friendly.

Check "Data\scripts\scr\gui.c" in my MixMasters for a working example text example. You can still use more advanced line features for color type bars or even just use images.

Offline NickyP

  • Hero Member
  • *****
  • Posts: 2772
  • You know, that guy with the pet drum?
    • Personal OpenBOR site.
Re: Draw player health to screen with fonts/numbers
« Reply #2 on: December 09, 2011, 01:33:14 am »
Look at one of my betas, Tales of Final Fantasy. I display both health and MP as numbers in that one.

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #3 on: December 09, 2011, 01:36:09 am »
Thanks guys I'll check them out.

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #4 on: December 09, 2011, 03:14:37 am »
I did it using NickyP's script, thou I'm not sure I learnt much, I can understand what's going on in it.  ;)



I'll still try writing my own as a learning process and try different methods, I'm eventually going to create the HUD from scratch in script too so I'll start building on this to display the doomguy FACE based on health.  Gonna check out what you've done now MatMan in your mod.

 :cheers!:

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #5 on: December 11, 2011, 12:00:13 am »
Believe it or not I managed to kind of make some headway with this, although it's probably not very well done, it's encouraging to me at least getting something to work.

I've got the doomguy FACE displaying based on current health,


Im still not sure how set it up to be animated, Im guessing it's an elapsed time thing but I diddnt wanna break what I had trying it just yet.  Also wasn't sure where to continue, whether to keep using update.c or utilise didhitscript etc or something to do the face changes for PAINS, GET ITEM/WEAPON etc.  Each needs to be displayed based on current health.  Also there is faces for when he is attacking enemies which would also be cool to add eventually.

As far as the rest of the DOOM STBAR (STAT BAR) I started to work on it but it will need consideration as later on it will need room for displaying armor, ammo types etc.  As well as leaving room to have at least players 2 players with full statbars (4 could be done unless it just fills too much space on the screen)



I've decided to just hide the scores now, they can just be tallied at the end of each level.




Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Draw player health to screen with fonts/numbers
« Reply #6 on: December 11, 2011, 12:10:21 am »
Quote
Also wasn't sure where to continue, whether to keep using update.c or utilise didhitscript etc or something to do the face changes for PAINS, GET ITEM/WEAPON etc.

 I believe you should use both. Takedamagescript stores a temporary hit status on a variable (entity variable or global one) then updatescript changes face based on this hit status. After this, updatescript will reset that hit status and thus restore face to previous state.
 Should be the same for weapon although not sure what script is triggered when weapon is picked up.
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #7 on: December 11, 2011, 12:16:00 am »
Cool I hoped thats how it would work.

Quote
Should be the same for weapon although not sure what script is triggered when weapon is picked up.

Yeah thats had me stumpted too so I haven't got anywhere with weapons yet, that will be the next goal thou.

Whoops meant to post the code before cause Im sure I'm doing this pretty rough.
Code: [Select]
// in update.c
void main()
{   
//
    void p1 = getplayerproperty(0, "entity");
    void p2 = getplayerproperty(1, "entity");
    void p3 = getplayerproperty(2, "entity");
    void p4 = getplayerproperty(3, "entity");
    char p1health;
    char p2health;
    char p3health;
    char p4health;

     
//HP text script
    if(getentityproperty(p1, "exists")) {
        int p1disphealth = getentityproperty(p1, "health");
        if(p1disphealth < 0) p1disphealth = 0;
if(p1disphealth <= 0) drawsprite(getglobalvar("facexx"), 4, 2, 3001, 0);
        p1health = p1disphealth;
        if(p1disphealth == 100)drawstring(36, 7, 3, p1health);
else if(p1disphealth < 100) drawstring(44, 7, 3, p1health);
else if(p1disphealth <= 9) drawstring(54, 7, 3, p1health);
drawstring(70, 9, 0, "%");
drawstring(82, 2, 0, "LIVES");
drawstring(82, 23, 0, "SCORE");
drawsprite(getglobalvar("p1stbar"), 1, 1, 999, 0);
drawsprite(getglobalvar("p1fbg"), -2, 1, 1000, 0);
if(p1disphealth >= 100) drawsprite(getglobalvar("faceb"), 4, 2, 2000, 0);
else if(p1disphealth >= 80) drawsprite(getglobalvar("faceb"), 4, 2, 2001, 0);
else if(p1disphealth <= 80) drawsprite(getglobalvar("facef"), 4, 2, 2001, 0);
if(p1disphealth <= 55) drawsprite(getglobalvar("facei"), 4, 2, 2002, 0);
if(p1disphealth <= 35) drawsprite(getglobalvar("facel"), 4, 2, 2003, 0);
if(p1disphealth <= 15) drawsprite(getglobalvar("faceo"), 4, 2, 2004, 0);
if(p1disphealth == 1) drawsprite(getglobalvar("faceo"), 4, 2, 2005, 0);
    }

just the player one part, editing the health as numbers script for now so I can see them working together.
« Last Edit: December 11, 2011, 12:18:38 am by BeasTie »

Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Draw player health to screen with fonts/numbers
« Reply #8 on: December 11, 2011, 12:28:19 am »
 Maybe didhitscript might do the trick? I've confirmed that it works on items when picked up so maybe it could be applied to weapons as well.
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #9 on: December 11, 2011, 12:48:49 am »
Good idea, I wasn't even sure if items would work the same as other ents.

What I meant before was not sure how to make it display 3 sprites in sequence, so face is animated when idle (his eyes/eybrows look/move left and right.) When I tried I ended up with all 3 images at once on top of eachother.  It got all the images loaded already, example 100% health idle animation would be something  like this

faceb - looking front
facea - looking right
faceb - looking front
facec - looking left



Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Draw player health to screen with fonts/numbers
« Reply #10 on: December 12, 2011, 11:07:56 pm »
 Hmmm... that means your face display function should use a check before displaying anything. Let's see:
 1st check hit state, if not hit go to 2. If hit, display the temporary hit face
 2nd check current health. Match displayed face with that.

 #1 is slightly complicated since it includes time.

 BTW I see that you use script to display the grey bar on the back and text (lives and score) too. Why don't you merge the text in the bar instead to save some resource? it's not like the text would change right?
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #11 on: December 13, 2011, 03:08:34 am »
yeah I was seeing how it would look, originally I already had lives etc. drawn on the greybar as the players icon.  Planned to still use the icon for some of the work because I liked how the player icon also flashed on hit from the blink.c script, but OpenBoR always draws the icon on top of the scripted graphics.

For armor, ammo etc.  I think I'll use small icons with the small fonts next to them for amounts.  Probably only way to make it fit, some recent doom ports do ammo like this it looks pretty cool.

I wasnt quite sure how openborvariant 'elapsedtime' is supposed to work.  Can I use it to make drawsprite display for fixed time ?

Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Draw player health to screen with fonts/numbers
« Reply #12 on: December 14, 2011, 10:56:32 pm »
Quote
I wasnt quite sure how openborvariant 'elapsedtime' is supposed to work.  Can I use it to make drawsprite display for fixed time ?

 Actually, updatescript is run per game tick so if you run something like drawstring, it displays the string again n again. If you run drawstring elsewhere, in animationscript for instance, the string will be displayed very brief before it's gone.

 So instead of displaying for fixed time, you should control how long updatescript will run drawsprite.
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline BeasTie

  • Hero Member
  • *****
  • Posts: 760
Re: Draw player health to screen with fonts/numbers
« Reply #13 on: May 30, 2012, 12:39:09 am »
Made some more headway, adding a few lines like this I've got the the pain, get, idle faces working by checking what ANIM is playing as well as current hp.
Code: [Select]
//DISPLAY PAIN FACE DURING PAIN ANIM - BASED ON CURRENT HP
if(anim == openborconstant("ANI_PAIN") && (p1disphealth >= 80)) drawsprite(getglobalvar("faceq"), 8, 3, 3002, 0);

I still haven't worked out how to tell it how long to run drawsprite commands for, once I get that sorted it will work perfect.  I tried running the script for the different IDLE faces in timetick.c and updated.c instead but it just had the same effect.

Also I been trying to get it to check what direction player is facing for the pain faces,  I kinda got the command for checking the direction
Code: [Select]
dir = getentityproperty(self, "direction");but not sure how to add it to my statement to check what dir equals.

Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Draw player health to screen with fonts/numbers
« Reply #14 on: May 30, 2012, 12:55:20 am »
 Seems good enough!

Quote
I still haven't worked out how to tell it how long to run drawsprite commands for, once I get that sorted it will work perfect.

 If you have synch it with player's animation, there's no need for time control anymore since updatescript will revert to normal face after PAIN (for instance) is ended.

Quote
but not sure how to add it to my statement to check what dir equals.

 Hmmm.... I don't know the function for this but this calls for mirroring the drawn sprite.
 You script might be like this:

Quote
if(dir==0){// Facing left?
  Drawsprite function should be declared here in mirrored state
 } else {//Facing right?
  Drawsprite function should be declared here without mirroring
 }
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

 



 0%




SimplePortal 2.3.3 © 2008-2010, SimplePortal