View Single Post
  #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)) {
    
x = player.x - 1.5;
    
y = player.y - 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.i = 0;
  
// Clear Drawing Array
  
this.drawing = {};
  
// Hide Images
  
hideimgs(200, 2000);
  for (
temp.p: players) {
    
// Draw Block For Each Player
    
with (findimg(200 + temp.i)) {
      
x = temp.p.x + 1;
      
y = temp.p.y + 3;
      
image = "block.png";
    }
    
// Add Player Object and Block ID to Drawing Array
    
this.drawing.add({temp.p, 200 + 1});
    
// Increment temp.i
    
temp.i++;
  }
}

function 
updateInfo() {
  for (
temp.draw: this.drawing) {
    
temp.p = temp.draw[0];
    
with (findimg(temp.draw[1])) {
      
x = temp.p.x + 1;
      
y = temp.p.y + 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