Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Circular HUD Bar (https://forums.graalonline.com/forums/showthread.php?t=134259457)

DustyPorViva 06-10-2010 11:37 AM

Circular HUD Bar
 
2 Attachment(s)
Made this for fun. It was intended to be a health bar like Kingdom Hearts, but I got a bit stumped when it came to branching the bar off from the angle. Either way, I figured I'd fix this up and post it as a script for others to use or even better, learn.

Right now the bar itself extends per your health(it's based on player.hearts and player.fullhearts, if you're using custom, replace all instances of player.fullhearts with your custom maxHP, and player.hearts with your custom HP), so make sure you define the maximum amount of possible life(for example, 20 is set for mines since default hearts max out at 20).

Attachment 51169

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.HUDimage   "dusty_guibartest1.png"// Define the image of the bar;
  
showstats(1024);        // Hide all but the player
  
this.HUDx       50;   // Center 'X' position of the HUD
  
this.HUDy       50;   // Center 'Y' position of the HUD
  
this.radius     23;   // Distance the bar extends out to from center
  
this.thickness  15;   // Thickness of bar in pixels
  
this.margin     2;    // Thickness of outline in pixels
  
this.startangle pi/2// Starting angle of bar
  
this.direction  1;    // Direction the bar goes. -1 = left, 1 = right
  
this.maxlife    20;   // Define the max amount of life possible

  
onTimeout();
}

function 
onTimeout() {
  
// RECORD CUSTOMIZATIONS INTO TEMPORARY VARIABLES
  // THIS IS SIMPLY FOR THE EASE OF SHORTER VARIABLE NAMES
  
temp.sa this.startangle;
  
temp.ox this.HUDx;
  
temp.oy this.HUDy;
  
temp.this.radius;
  
temp.this.thickness;
  
temp.this.margin;

  
// DISPLAY THE HEART IMAGE
  // THIS CAN BE CHANGED TO SOMETHING LIKE THE PLAYER'S HEAD
  
with (findimg(1000)) {
    
image "state.png";
    
ox 20;
    
oy 22;
    
partw 40;
    
parth 44;
    
layer 6;
  }

  
// ALTER THE 'FILL'. THIS IS A VARIABLE THAT COUNTS UP
  // OR DOWN TO THE PLAYER'S HEARTS, SO WE CAN USE IT AS
  // AN ALTERNATIVE, THUS ANIMATING THE BAR FILLING
  
if (this.fill != player.heartsthis.fill += (this.fill player.hearts) ? .5 : -.5;
  else 
this.fill player.hearts;

  
// IF NEW IMAGE COUNT IS LESS THAN THE OLD, HIDE EXCESSIVE IMAGES
  
if (this.oldi player.fullhearts*2hideimgs(200,300+this.oldi);

  for (
temp.i=0;i<player.fullhearts*2;i++) {
    
temp.seg pi/this.maxlife;
    
temp.= (sa + (i*seg)*this.direction);
    
temp.padding = {(== 0)*pi/40,(((i+1)/2) == player.fullhearts)*pi/40};
    
with (findimg(200+i)) {
      
polygon = {
        
ox cos(padding[0])*(r+t)      ,oy sin(padding[0])*(r+t)      ,
        
ox cos(seg padding[1])*(r+t),oy sin(seg padding[1])*(r+t),
        
ox cos(seg padding[1])*r    ,oy sin(seg padding[1])*r    ,
        
ox cos(padding[0])*r          ,oy sin(padding[0])*r          ,
      };
      
red blue green 0;
      
alpha 1;
      
layer 4;
    } 

    if (
this.fill*2) {
      
with (findimg(300+i)) {
        
polygon = {
          
ox cos(a)*(r+t-m)      ,oy sin(a)*(r+t-m)      ,
          
ox cos(seg)*(r+t-m),oy sin(seg)*(r+t-m),
          
ox cos(seg)*(r+m)  ,oy sin(seg)*(r+m)  ,
          
ox cos(a)*(r+m)        ,oy sin(a)*(r+m)        ,
        };
        
image thiso.HUDimage;
        
layer 5;
      }
    } else 
hideimg(300+i);
  }
  
this.oldi i// RECORD THIS IMAGE COUNT AS OLD

  // IF BAR IS FILLED, SET A LONGER TIMEOUT FOR EFFICIENCY, OTHERWISE
  // SET IT AS LOW AS POSSIBLE FOR SMOOTHER FILL ANIMATION
  
setTimer(this.fill == player.hearts 0.25 0.05);


If I figure out how, I may eventually also add the Kingdom Hearts version. Also, the image for the bar is attached. Make sure you download and save this appropriately.

cbk1994 06-10-2010 12:51 PM

That's really cool, nice work. I would have had no idea how to do this without a ton of images :p.

maximus_asinus 06-10-2010 01:51 PM

amazing Dusty, great work.

Fulg0reSama 06-10-2010 04:03 PM

Extremely good work man

Cloven 06-10-2010 04:04 PM

Yeah that's definitely very nice work Dusty. :D

adam 06-10-2010 05:20 PM

Good work Dusty.

coreys 06-10-2010 06:10 PM

Amazing work, Dusty

xAndrewx 06-10-2010 07:41 PM

Haha, so this is what you were talking about earlier!!! good job tuff guy

Tigairius 06-10-2010 08:20 PM

Good stuff.

DustyPorViva 06-10-2010 08:22 PM

Quote:

Originally Posted by xAndrewx (Post 1581248)
Haha, so this is what you were talking about earlier!!! good job tuff guy

Something a little different, but ya :) I was hoping to do something like this:
http://www.whattheyplay.com/media/im...creenshot.jpeg
But so far I've had no luck figuring it out.

Cubical 06-10-2010 08:55 PM

Why not use multiple images and check the players hp each time they are hit to figure out which image to change. I could see it done with like4 or 5 images

adam 06-10-2010 09:07 PM

That's not nearly as cool though.

Chompy 06-10-2010 11:03 PM

Quote:

Originally Posted by DustyPorViva (Post 1581252)
Something a little different, but ya :) I was hoping to do something like this:
http://www.whattheyplay.com/media/im...creenshot.jpeg
But so far I've had no luck figuring it out.

I would rep you for that image alone.

I really like this code of yours. It's always been kinda "weird" always either having to do vertical or horizontal lines when displaying some kinds of values, but this is really cool.

I'll have to play around with this, thanks! :D

Seich 06-11-2010 02:34 AM

^^ That's really neat. It gave me a bunch of random ideas to where HUDs could be taken.

DustyPorViva 06-15-2010 04:02 AM

Quote:

Originally Posted by Cubical (Post 1581261)
Why not use multiple images and check the players hp each time they are hit to figure out which image to change. I could see it done with like4 or 5 images

Hmm, I've only just seen this. Do you mean a predefined set of images to account for every amount of health? Ya, sure, it could be done... but at what cost? 4 or 5 images would only account for 4 or 5 possible status of health(it would only work for someone with 2-3 hearts). After that, you start to lose accuracy as you don't have an image for all the possible increments. Someone with 20 hearts would need 40 images to account for every instance(.5 hp, 1 hp, 1.5hp... so on and so forth).

The method I used is much more dynamic, and can be used with custom systems to display even higher values of HP(up to the 100-200's and really... no limit).

edit: I guess it's not optimized for larger numbers, but I guess that'll be my next goal!

salesman 06-15-2010 04:23 AM

you should probably lose the timeout for custom systems though

Emera 04-10-2011 11:08 AM

Can you release a gralat showing version too please. Players cant see their gralats. ;3

Tricxta 04-10-2011 11:58 AM

nice necropost noob, also graalats have no max so therefore this couldnt be applied to money if thats what you were trying to say. If its just as simple as adding a image of a graalat then some text saying how much you have SHAME ON YOU!!!

Demisis_P2P 04-10-2011 12:24 PM

Quote:

Originally Posted by Tricxta (Post 1642419)
If its just as simple as adding a image of a graalat then some text saying how much you have SHAME ON YOU!!!

Yeah, I'm pretty sure this is what he wants. Which he could learn to do in about 10 minutes if he wanted to.

skillmaster19 04-10-2011 03:28 PM

Quote:

Originally Posted by Demisis_P2P (Post 1642421)
Yeah, I'm pretty sure this is what he wants. Which he could learn to do in about 10 minutes if he wanted to.

Isn't that a default system?

Demisis_P2P 04-10-2011 08:26 PM

Quote:

Originally Posted by skillmaster19 (Post 1642425)
Isn't that a default system?

Yeah but it's hidden in the 4th line of Dusty's script, which is even conveniently commented.

NPC Code:
showstats(1024);        // Hide all but the player



And then a search on GraalBible for ShowStats brings up this page which explains everything and even provides a perfect example of what needs to be done to show the player's gralat count.

fowlplay4 04-10-2011 08:32 PM

Quote:

Originally Posted by Tricxta (Post 1642419)
graalats have no max

Yes they do. It's roughly 3.7 million.


All times are GMT +2. The time now is 02:21 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.