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 11-03-2011, 02:25 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Health bar

Well Iīm trying to make a health bar in a gani. I was looking around the forums for help and my result was this:

PHP Code:
SCRIPT
function onPlayerEnters() {
  
hideimgs(2003000);
  
temp.pl findplayer(player.account);
  
with (findimg(200)) {
    
player.2/16;
    
player.1.75;
    
image "pirate_healthbar.png";
    
width maxWidth;
    
height maxHeight;
    
attachtoowner true;
  }
  
with (findimg(201+pl.id)) {
    
player.10/16;
    
player.1.75 3/16;
    
image "pirate_healthbar-progress.png";
    
width getimgwidth(image);
    
height getimgheight(image);
    
attachtoowner true;
  }
  
part=(pl.clientr.health_hearts/pl.clientr.health_fullhearts)*findimg(201+pl.id).width;
  
changeimgpart(201+pl.idfindimg(201+pl.id).width-part0partfindimg(201+pl.id).height); 
}
SCRIPTEND 
I know itīs not updating constantly but thats not my problem. My problem is that it shows the clients hp in the correct form. But the bar at the other players keeps saying that the player has 100% health even when itīs not true.

How can I fix it?
__________________
MEEP!
Reply With Quote
  #2  
Old 11-03-2011, 02:35 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by callimuc View Post
Well Iīm trying to make a health bar in a gani. I was looking around the forums for help and my result was this:

PHP Code:
SCRIPT
function onPlayerEnters() {
  
hideimgs(2003000);
  
temp.pl findplayer(player.account);
  
with (findimg(200)) {
    
player.2/16;
    
player.1.75;
    
image "pirate_healthbar.png";
    
width maxWidth;
    
height maxHeight;
    
attachtoowner true;
  }
  
with (findimg(201+pl.id)) {
    
player.10/16;
    
player.1.75 3/16;
    
image "pirate_healthbar-progress.png";
    
width getimgwidth(image);
    
height getimgheight(image);
    
attachtoowner true;
  }
  
part=(pl.clientr.health_hearts/pl.clientr.health_fullhearts)*findimg(201+pl.id).width;
  
changeimgpart(201+pl.idfindimg(201+pl.id).width-part0partfindimg(201+pl.id).height); 
}
SCRIPTEND 
I know itīs not updating constantly but thats not my problem. My problem is that it shows the clients hp in the correct form. But the bar at the other players keeps saying that the player has 100% health even when itīs not true.

How can I fix it?
There are atleast 2 key problems here.

First, you cannot read clientr. variables of other players on your own client. This is where health would need to be stored as part of an attribute.
So essentially this is attempting to show a bar with 0 width, which actually shows the entire bar and makes it look as if it's 100% full.

The second problem is that even if you had HP working properly you don't seem to have a mechanism for updating the display upon HP being changed, unless you're just re-initialising the gani as part of the attribute upon players being damaged?

On a side note it is pointless to be doing pl = findplayer(player.account); as you already have the player object. You also do not need to be referring to pl.id as part of the display index as these displays are on the gani attribute of each player and cannot collide. This also means you do not need to be doing hideimgs(200, 3000); .
Reply With Quote
  #3  
Old 11-03-2011, 02:41 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
Try reading this thread:
http://forums.graalonline.com/forums...hp?t=134264542

I made a post in there that should help you out.
__________________
Quote:
Reply With Quote
  #4  
Old 11-03-2011, 02:41 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by ffcmike View Post
First, you cannot read clientr. variables of other players on your own client. This is where health would need to be stored as part of an attribute.
So essentially this is attempting to show a bar with 0 width, which actually shows the entire bar and makes it look as if it's 100% full.
Oh thanks.

Quote:
Originally Posted by ffcmike View Post
The second problem is that even if you had HP working properly you don't seem to have a mechanism for updating the display upon HP being changed, unless you're just re-initialising the gani as part of the attribute upon players being damaged?
Already said that I knew that and wanted to fix the other thing at first . But I wanted to have it shown up as soon as the player was damaged.
__________________
MEEP!
Reply With Quote
  #5  
Old 11-03-2011, 04:23 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
Try reading this thread:
http://forums.graalonline.com/forums...hp?t=134264542

I made a post in there that should help you out.
Jea I took a look at tit and while testing it it seems like I did something wrong cause now I tried it and it worked

Well what is better to use: A gani scripted one or in a waepon? Like itīs said above it should only pop up for a time when the player is being damaged.
__________________
MEEP!
Reply With Quote
  #6  
Old 11-03-2011, 04:51 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
Depending on how your damage is handled you could just do something like this with showani and scheduleevent.

PHP Code:
//#CLIENTSIDE
function onDamage(amount) {
  
showani(100player.xplayer.y0"your_damage_gani"hp_ratio);
  
this.scheduleevent(2"HideDamage""");
}

function 
onHideDamage() {
  
hideimg(100);

You'll be able to use params[0]/hp_ratio to determine how much of the bar you'll need to show.
__________________
Quote:
Reply With Quote
  #7  
Old 11-03-2011, 04:57 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Well Iīm adding the gani to the players attributes whenever the player is hit (also changes the health than). And I made something like this in the gani
PHP Code:
SCRIPT
function onPlayerEnters() {
  
hideimgs(200201);
  
temp.pl findplayer(player.account);
  
with (findimg(200)) {
    
player.2/16;
    
player.1.75;
    
image "pirate_healthbar.png";
    
width maxWidth;
    
height maxHeight;
    
attachtoowner true;
  }
  
with (findimg(201)) {
    
player.10/16;
    
player.1.75 3/16;
    
image "pirate_healthbar-progress.png";
    
width getimgwidth(image);
    
height getimgheight(image);
    
attachtoowner true;
  }
  
part=(pl.attr[28]/pl.attr[29])*findimg(201).width;
  
changeimgpart(201findimg(201).width-part0partfindimg(201).height); 
  
settimer(3);
}

function 
onTimeOut() {
  for (
temp.1temp.=> 0temp.-= 0.01) {
    
changeimgcolors(200iiii);
    
changeimgcolors(201iiii);
    
sleep(0.05);
  }
  if (
findimg(200).alpha == || findimg(201).alpha == 0player.attr[2] = "";
}
SCRIPTEND 
__________________
MEEP!
Reply With Quote
  #8  
Old 11-03-2011, 05:00 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 callimuc View Post
Well Iīm adding the gani to the players attributes whenever the player is hit (also changes the health than). And I made something like this in the gani
I don't think you can edit attrs in ganis. Just take the code I posted above and set an attr and unset it instead of using showani/hideimg.
__________________
Quote:
Reply With Quote
  #9  
Old 11-03-2011, 05:09 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
I don't think you can edit attrs in ganis. Just take the code I posted above and set an attr and unset it instead of using showani/hideimg.
Well it worked for me. In an other script I had player.chat = player.attr[2]; and everything was fine. But Iīll try out your method.
__________________
MEEP!
Reply With Quote
  #10  
Old 11-03-2011, 07:38 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
Try reading this thread:
http://forums.graalonline.com/forums...hp?t=134264542

I made a post in there that should help you out.
I was testing out the site fp4 suggested and wasnīt sure how I should draw 2 images (since my health bar is out of 2 images).

Should I just start the 2nd image starting with an index of like 3000 or what?
__________________
MEEP!
Reply With Quote
  #11  
Old 11-03-2011, 08:06 PM
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
This also works:

PHP Code:
temp.0;
for (
temp.pplayers) {
  
with (findimg(200 temp.i)) {
    
// BAR
  
}
  
with (findimg(200 temp.i)) {
    
// BAR CONTENTS
  
}
  
temp.+= 2;

__________________
Quote:
Reply With Quote
  #12  
Old 11-03-2011, 09:26 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Ahh didnt think of that
__________________
MEEP!

Last edited by callimuc; 11-04-2011 at 01:41 AM.. Reason: nvm
Reply With Quote
  #13  
Old 11-04-2011, 01:41 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Well I played around with that and got this:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
settimer(0.05);
}

function 
onPlayerEnters() {
  
this.lastsize 0;
  
settimer(0.05);
}

function 
onTimeout() {
  if (
players.size() != this.lastsize) {
    
drawInfo();
    
this.lastsize players.size();
  }
  else 
updateInfo();
  
setTimer(0.05);
}

function 
drawInfo() {
  
temp.0;
  
this.drawing1 = {};
  
this.drawing2 = {};
  
hideimgs(2003000);
  for (
temp.pplayers) {
    
with (findimg(200 temp.i)) {
      
p.2/16;
      
p.1.75;
      
width getimgwidth(image);
      
height getimgheight(image);
      
image "pirate_healthbar.png";
    }
    
with (findimg(200 temp.i)) {
      
findimg(200 temp.i).8/16;
      
findimg(200 temp.i).3/16;
      
width getimgwidth(image);
      
height getimgheight(image);
      
image "pirate_healthbar-progress.png";
    }
    
this.drawing1.add({temp.p200 i});
    
this.drawing2.add({temp.p200 temp.i});
    
part=(p.attr[28]/temp.p.attr[29])*findimg(this.drawing2[1]).width;
    
changeimgpart(this.drawing2[1], findimg(this.drawing2[1]).width-part0partfindimg(this.drawing2[1]).height);
  }
  
temp.+= 2;
}

function 
updateInfo() {
  for (
temp.pplayers) {
    
with (findimg(this.drawing1[1])) {
      
p.2/16;
      
p.1.75;
    }
    
with (findimg(this.drawing2[1])) {
      
findimg(200 temp.i).8/16;
      
findimg(200 temp.i).3/16;
    }
    
part = (p.attr[28]/temp.p.attr[29])*findimg(this.drawing2[1]).width;
    
changeimgpart(this.drawing2[1], findimg(this.drawing2[1]).width-part0partfindimg(this.drawing2[1]).height);
  }


My problem is that it wonīt update the progress and itīs only shown on one player.
How can I fix that?
__________________
MEEP!
Reply With Quote
  #14  
Old 11-04-2011, 02:01 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Maybe increase an index variable, say for instance.
PHP Code:
for(temp.ind players){
temp.indx ind.account.substring(1);
with(findimg(200) + temp.indx){ 
Im not sure of something like that would work but idk.
The problem is your using one image to display everyones health, I think you need some sort of index so that you can show dynamic text.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #15  
Old 11-04-2011, 04:11 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
You're looping through each player and only using the element 1 in the array. I believe there was an error in my code unfortunately I can't go back and edit it now.

In your drawing function record the following in an array:

this.drawing.add({temp.p, 200 + temp.i});

In your updating function loop through your drawing array:

PHP Code:
for (temp.drawthis.drawing) {
  
temp.plyr temp.draw[0];
  
temp.img_index temp.draw[1];
  
with (findimg(temp.img_index)) {
    
// Update position
    
temp.plyr.x;
    
temp.plyr.y;
  }
  
with (findimg(temp.img_index 1)) {
    
// Update position
  
}

Also just some small optimizations/changes you can make as well:

1. Store the width and height of your bar graphics in a variable outside the loop. Calling getimgwidth and getimgheight repeatedly isn't needed.
2. Use partx, party, partw, and parth instead of changeimgpart since you're already using findimg in a with statement.

PHP Code:
// Using part in findimg assignments
with (findimg(200)) {
  
image "head0.png";
  
partx 0;
  
party = (32 2);
  
partw 32;
  
parth 32;
}
// Same thing as doing:
changeimgpart(200032 23232); 
3. Be more consistent when using temp. In the same line you use it with and without the prefix. Avoid setting global variables (your line part=math+blah that don't need to be global. You can do that by putting temp. I.e: temp.part.
__________________
Quote:
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 10:31 PM.


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