Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Health for HUD (https://forums.graalonline.com/forums/showthread.php?t=134260566)

brasilboy109 09-18-2010 09:43 PM

Health for HUD
 
everytime i get hurt nothing happenes but when i update the scripts it shows the correct ammount of hearts.... Idk how to update it

any ideas to make it better and or be able to update the health?


PHP Code:

// Scripted by *brasilboy109
//#CLIENTSIDE
function onCreated(){
timeout=0.05;

/* HEALTH SCRIPT V1.0 MADE BY BRASILBOY109 */
/* IMGAES MADE BY PAVILION75 */
}

function 
onTimeout(){
if(
player.hearts>=0.5){
  
showimg(500,"pavilion75-red-heart-half.png",1000,25);
  
changeimgzoom(500,1);
  
changeimgvis(500,4);
}

//health 1 image
if(player.hearts>=1){
  
showimg(501,"pavilion75-red-heart.png",1000,25);
  
changeimgzoom(501,1);
  
changeimgvis(501,4);
}


//health 1.5 image
if(player.hearts>=1.5){
  
//health 0.5 image
  
showimg(502,"pavilion75-red-heart-half.png",1050,25);
  
changeimgzoom(502,1);
  
changeimgvis(502,4);
}

//health 2 image
if(player.hearts>=2){
  
//health 0.5 image
  
showimg(503,"pavilion75-red-heart.png",1050,25);
  
changeimgzoom(503,1);
  
changeimgvis(503,4);
}
if(
player.hearts>=2.5){
  
//health 0.5 image
  
showimg(504,"pavilion75-red-heart-half.png",1100,25);
  
changeimgzoom(504,1);
  
changeimgvis(504,4);
}
if(
player.hearts>=3){
  
//health 0.5 image
  
showimg(505,"pavilion75-red-heart.png",1100,25);
  
changeimgzoom(505,1);
  
changeimgvis(505,4);

}if(
player.hearts>=3.5){
  
//health 0.5 image
  
showimg(506,"pavilion75-red-heart-half.png",1150,25);
  
changeimgzoom(506,1);
  
changeimgvis(506,4);
}if(
player.hearts>=4){
  
//health 0.5 image
  
showimg(507,"pavilion75-red-heart.png",1150,25);
  
changeimgzoom(507,1);
  
changeimgvis(507,4);
}if(
player.hearts>=4.5){
  
//health 0.5 image
  
showimg(508,"pavilion75-red-heart-half.png",1200,25);
  
changeimgzoom(508,1);
  
changeimgvis(508,4);
}if(
player.hearts>=5){
  
//health 0.5 image
  
showimg(509,"pavilion75-red-heart.png",1200,25);
  
changeimgzoom(5009,1);
  
changeimgvis(509,4);
}if(
player.hearts>=5.5){
  
//health 0.5 image
  
showimg(510,"pavilion75-red-heart-half.png",1250,25);
  
changeimgzoom(510,1);
  
changeimgvis(510,4);
}if(
player.hearts>=6){
  
//health 0.5 image
  
showimg(511,"pavilion75-red-heart.png",1250,25);
  
changeimgzoom(511,1);
  
changeimgvis(511,4);
  }
  
timeout=0.05;
  } 


12171217 09-18-2010 10:16 PM

lol.. well that's one way to do it..

To simply answer your first question, you have to hide the images as well.

hideimg(index); to hide a single showimg.
or
hideimgs(min index, max index); to do a range.

Other than that, your scripting is extremely distasteful, but I suppose it'll work and I don't care to tell you much more than that.

Also, use setTimer(.05); instead of timeout=.05;

Here's a hint for making it better:
PHP Code:

function onPlayerEnters() {
  
onTimeOut();
}
function 
onTimeOut() {
  
setTimer(.05);
  
hideimgs(300this.images);  //Clear the old images
  
this.images 300;  //Start a new image counter
  
temp.maxHearts 5//Max heart count
  
for (temp.i=0;temp.i<temp.maxHearts;temp.i++) { //Loop through the possible heart values
    
if (temp.i>player.hearts) break; //Dont exceed the players heart count
    
this.images++; //"Allocate" a new image
    
showimg(this.images"block.png"32+temp.i*4832); //Draw the heart at the proper position.
    
findimg(this.images).layer 5//Screen-relative layer
  
}


Ya. If something doesn't work or whatever, I did type this on my phone.. But I hope you appreciate that little snippet.
}

brasilboy109 09-18-2010 11:48 PM

Quote:

Originally Posted by 12171217 (Post 1601402)
lol.. well that's one way to do it..

To simply answer your first question, you have to hide the images as well.

hideimg(index); to hide a single showimg.
or
hideimgs(min index, max index); to do a range.

Other than that, your scripting is extremely distasteful, but I suppose it'll work and I don't care to tell you much more than that.

Also, use setTimer(.05); instead of timeout=.05;

Here's a hint for making it better:
PHP Code:

function onPlayerEnters() {
  
onTimeOut();
}
function 
onTimeOut() {
  
setTimer(.05);
  
hideimgs(300this.images);  //Clear the old images
  
this.images 300;  //Start a new image counter
  
temp.maxHearts 5//Max heart count
  
for (temp.i=0;temp.i<temp.maxHearts;temp.i++) { //Loop through the possible heart values
    
if (temp.i>player.hearts) break; //Dont exceed the players heart count
    
this.images++; //"Allocate" a new image
    
showimg(this.images"block.png"32+temp.i*4832); //Draw the heart at the proper position.
    
findimg(this.images).layer 5//Screen-relative layer
  
}


Ya. If something doesn't work or whatever, I did type this on my phone.. But I hope you appreciate that little snippet.
}

Yea thanks that helped alot.

cbk1994 09-18-2010 11:51 PM

You should use
PHP Code:

function onCreated() { 
  
onTimeOut(); 


instead of
PHP Code:

function onPlayerEnters() { 
  
onTimeOut(); 


Timeouts don't cancel when you enter a level.

MattKan 09-19-2010 12:12 AM

How does he make it so that the hearts appear in the top right corner of the screen for all screen sizes?

Soala 09-19-2010 12:50 AM

Quote:

Originally Posted by MattKan (Post 1601410)
How does he make it so that the hearts appear in the top right corner of the screen for all screen sizes?

You can use function GraalControl.onResize and use the coordinates (x and y) you always want your image to show at.

fowlplay4 09-19-2010 01:01 AM

Quote:

Originally Posted by MattKan (Post 1601410)
How does he make it so that the hearts appear in the top right corner of the screen for all screen sizes?

Relative positioning using screenwidth and screenheight. I.e:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
// Centered Block
  
with (findimg(200)) {
    
screenwidth 2;
    
screenheight 2;
    
image "block.png";
    
layer 4;
  }
  
// Top Right Block
  
with (findimg(201)) {
    
screenwidth 64;
    
64;
    
image "block.png";
    
layer 4;
  }
  
// Bottom Right
  
with (findimg(202)) {
    
screenwidth 64;
    
screenheight 64;
    
image "block.png";
    
layer 4;
  }



brasilboy109 09-19-2010 01:27 AM

so it'd be like???

PHP Code:

  //player hearts 0.5
  
showimg(201,"pavilion75-red-heart-heart.png",850,25);
  
changeimgzoom(201,1);
  
changeimgvis(201,4);
    
with (findimg(201)) { 
    
screenwidth 64
    
64
    
image "pavilion-red-heart.png"
    
layer 4
  } 

???

MrOmega 09-19-2010 03:07 AM

Quote:

Originally Posted by Soala (Post 1601414)
You can use function GraalControl.onResize and use the coordinates (x and y) you always want your image to show at.

Here's an example. ( I couldn't understand how to do it when I first started scripting) =
PHP Code:


function GraalControl.onReSize()
{

  
findimgID).VAL;
  
findimgID).VAL;



Quote:

Originally Posted by brasilboy109 (Post 1601417)
so it'd be like???

PHP Code:

  //player hearts 0.5
  
showimg(201,"pavilion75-red-heart-heart.png",850,25);
  
changeimgzoom(201,1);
  
changeimgvis(201,4);
    
with (findimg(201)) { 
    
screenwidth 64
    
64
    
image "pavilion-red-heart.png"
    
layer 4
  } 

???

an easier way would be
PHP Code:

//player hearts 0.5
  
with (findimg(201))
  { 
    
layer 4
    
screenwidth 64
    
64
    
image "pavilion-red-heart.png"
    
zoom 1;    
  } 


salesman 09-19-2010 03:50 PM

it's been a while, but are screenwidth and GraalControl.width essentially the same thing? or does screenwidth/height always return the monitor resolution regardless of the size of the game window?

Crow 09-19-2010 04:03 PM

Quote:

Originally Posted by salesman (Post 1601461)
it's been a while, but are screenwidth and GraalControl.width essentially the same thing? or do screenwidth/screenheight always return the monitor resolution regardless of the size of the game window?

It's possible they are the same thing, but I've been using GraalControl.width ever since we got it. Maybe screenwidth returns the width of the Graal window (GraalControl possibly being smaller). Not sure about that though.

Skyld 09-19-2010 04:09 PM

Quote:

Originally Posted by Crow (Post 1601465)
It's possible they are the same thing, but I've been using GraalControl.width ever since we got it. Maybe screenwidth returns the width of the Graal window (GraalControl possibly being smaller). Not sure about that though.

GraalControl.width/height usually refer to the size of the Graal window unless you have changed the width/height of the GraalControl so that you can draw something outside of the GraalControl but still in the main Graal window (by adding child controls to GUIContainer), i.e. a chat box at the bottom of the screen that doesn't overlay on the level viewport.

Cubical 09-20-2010 03:03 AM

I usually prefer using gui controls to make guis and just creating custom profiles for each of the controls I use.

edit: http://wiki.graal.net/index.php/Crea...iControls_List


All times are GMT +2. The time now is 06:49 PM.

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