View Single Post
  #2  
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