Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-13-2011, 03:21 AM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
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
__________________
Reply With Quote
  #2  
Old 09-13-2011, 03:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #3  
Old 09-13-2011, 03:32 AM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
Quote:
Originally Posted by cbk1994 View Post
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 
__________________
Reply With Quote
  #4  
Old 09-13-2011, 03:48 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #5  
Old 09-13-2011, 04:41 AM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
Quote:
Originally Posted by cbk1994 View Post
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
__________________
Reply With Quote
  #6  
Old 09-13-2011, 04:59 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Ohk4y View Post
- 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.
__________________
Quote:

Last edited by fowlplay4; 09-13-2011 at 05:10 AM..
Reply With Quote
  #7  
Old 09-13-2011, 05:04 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Ohk4y View Post
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.
__________________
Reply With Quote
  #8  
Old 09-13-2011, 05:26 AM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
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.
Reply With Quote
  #9  
Old 09-13-2011, 06:47 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
I thought it was less then 250 that shows serverside :S
Reply With Quote
  #10  
Old 09-13-2011, 01:20 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Tricxta View Post
I thought it was less then 250 that shows serverside :S
No, it's < 200.
__________________
Reply With Quote
  #11  
Old 09-13-2011, 05:43 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of light
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Quote:
Originally Posted by Tricxta View Post
I thought it was less then 250 that shows serverside :S
When did you ever here that?
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:50 PM.


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