Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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
  #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
  #3  
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:09 PM.


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