Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Help with image part and gani. (https://forums.graalonline.com/forums/showthread.php?t=134264542)

Ohk4y 09-13-2011 03:21 AM

Help with image part and gani.
 
Hello,

I'm trying to make a health bar show up when you have a certain amount of health and change sizes above your head according to the amount of health you have.

Currently, showing the image above the players head works and shows for everyone supprisingly (it's placed in a gani and triggered with a weapon).

Though the issue I have is, the image part changes locally.. I really need it to show for everybody because it would be useless if it couldn't.
Here is the weapon I currently have:
PHP Code:

//#CLIENTSIDE
function onCreated() onTimeOut();
function 
onTimeOut() {
  if (
player.ani == "hurt") {
  
player.attr[11] = "e_hp.gani";
  }else{
  
player.attr[11] = null;
  } 
setTimer(.05);


Here is the Gani I currently have:
PHP Code:

SCRIPT

//#CLIENTSIDE
function onCreated() onTimeOut();
function 
onTimeOut() {
  
showimg(802,"hp_bar.png",player.x-1.5,player.y-1);
  
changeimgpart(802,0,0,clientr.player.stats.curhp*102/clientr.player.stats.maxhp,18);
  
findimg(802).zoom .5;
    if(
clientr.player.stats.curhp 1) {
      
hideimg(802);
    }
  
setTimer(.05);
}

SCRIPTEND 

Thanks in advance,
-Ohk4y

cbk1994 09-13-2011 03:25 AM

What's actually happening is that the script is being run on every player's computer since it's in a GANI script. The problem is that you can't access other players' clientr variables. You should put the health into another player.attr[] and use that instead of a clientr variable in the GANI.

Also, you don't need a timeout in your GANI. Try showing on onPlayerEnters and onCreated, and just set img.attachToOwner = true.

Ohk4y 09-13-2011 03:32 AM

Quote:

Originally Posted by cbk1994 (Post 1667991)
What's actually happening is that the script is being run on every player's computer since it's in a GANI script. The problem is that you can't access other players' clientr variables. You should put the health into another player.attr[] and use that instead of a clientr variable in the GANI.

Also, you don't need a timeout in your GANI. Try showing on onPlayerEnters and onCreated, and just set img.attachToOwner = true.

Like this?
PHP Code:

SCRIPT

//#CLIENTSIDE
function onPlayerEnters() {
  
showimg(802,"hp_bar.png",player.x-1.5,player.y-1);
  
changeimgpart(802,0,0,player.attr[28]*102/player.attr[28],18);
  
findimg(802).zoom .5;
  
findimg(802).attachToOwner true.
    if(
clientr.player.stats.curhp 1) {
      
hideimg(802);
    }
}

SCRIPTEND 


cbk1994 09-13-2011 03:48 AM

You have a period at the end of the attachToOwner instead of a semicolon, and you didn't change the clientr. variable near the hideImg. You also need to use a separate attr index for the maximum health value.

Ohk4y 09-13-2011 04:41 AM

Quote:

Originally Posted by cbk1994 (Post 1667996)
You have a period at the end of the attachToOwner instead of a semicolon, and you didn't change the clientr. variable near the hideImg. You also need to use a separate attr index for the maximum health value.

PHP Code:

SCRIPT

//#CLIENTSIDE
function onPlayerEnters() {
  
showimg(802,"hp_bar.png",player.x-1.5,player.y-1);
  
changeimgpart(802,0,0,player.attr[28]*102/player.attr[28],18);
  
findimg(802).zoom .5;
  
findimg(802).attachToOwner true;
    if(
player.attr[28] < 1) {
      
hideimg(802);
    }
}

SCRIPTEND 

player.attr[28] changes online

fowlplay4 09-13-2011 04:59 AM

Quote:

Originally Posted by Ohk4y (Post 1668002)
- script -

You can make that look cleaner by using findimg and a with statement.

PHP Code:

//#CLIENTSIDE
function onPlayerEnters() {
  
with (findimg(802)) {
    
player.1.5;
    
player.1;
    
image "hp_bar.png"// should probably make that less generic..
    
zoom 0.5;
    
partx party 0;
    
partw max(player.attr[28]*102/player.attr[28], 1);
    
parth 18;
    
attachToOwner true;
  }


I'm guessing the health bar shows all the time though, and onPlayerEnters probably won't make it update properly.

It's easier just use a Weapon-NPC and draw the HP bars over everyone's head instead of using an attr to display it.

I.e:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
}

function 
onPlayerEnters() {
  
// Force re-draw on level change
  // Probably not necessary if just changing levels on GMAP though
  
this.lastsize "";
}

function 
onTimeout() {
  
// Check if playercount in level changed
  
if (players.size() != this.lastsize) {
    
// Draw Info Blocks
    
drawInfo();
    
// Update last playercount
    
this.lastsize players.size();
  } else {
    
// Info blocks are still the same
    // Just update their X and Y instead
    
updateInfo();
  }
  
setTimer(0.05);
}

function 
drawInfo() {
  
// Initialize temp.i
  
temp.0;
  
// Clear Drawing Array
  
this.drawing = {};
  
// Hide Images
  
hideimgs(2002000);
  for (
temp.pplayers) {
    
// Draw Block For Each Player
    
with (findimg(200 temp.i)) {
      
temp.p.1;
      
temp.p.3;
      
image "block.png";
    }
    
// Add Player Object and Block ID to Drawing Array
    
this.drawing.add({temp.p200 1});
    
// Increment temp.i
    
temp.i++;
  }
}

function 
updateInfo() {
  for (
temp.drawthis.drawing) {
    
temp.temp.draw[0];
    
with (findimg(temp.draw[1])) {
      
temp.p.1;
      
temp.p.3;
    }
  }


or...

You can remove and re-add the attr everytime their health changes.

I.e:

PHP Code:

// Remove Attr To Force Update
player.attr[27] = "";
// Re-add Attr to Display Update
player.attr[27] = "healthbar.gani"

I would avoid floating too much information around a player though, it ends up overlapping and just becomes useless in crowded situations.

cbk1994 09-13-2011 05:04 AM

Quote:

Originally Posted by Ohk4y (Post 1668002)
player.attr[28] changes online

PHP Code:

changeimgpart(802,0,0,player.attr[28]*102/player.attr[28],18); 

You're using attr 28 as both the current health and the maximum health in this case, which is the problem.

oralgnome 09-13-2011 05:26 AM

If you have an index < 200 I believe the GUI will show for 'every' player. I remember because I was having a similar problem before.

Tricxta 09-13-2011 06:47 AM

I thought it was less then 250 that shows serverside :S

cbk1994 09-13-2011 01:20 PM

Quote:

Originally Posted by Tricxta (Post 1668011)
I thought it was less then 250 that shows serverside :S

No, it's < 200.

ff7chocoboknight 09-13-2011 05:43 PM

Quote:

Originally Posted by Tricxta (Post 1668011)
I thought it was less then 250 that shows serverside :S

When did you ever here that?


All times are GMT +2. The time now is 04:27 PM.

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