Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   [health script help] <read (https://forums.graalonline.com/forums/showthread.php?t=80646)

GULTHEX 07-20-2008 06:22 AM

[health script help] <read
 
ok when i press s to punch it turns my char invis but only if they have this script
and the punch script works fine allso
but this only happens if they have this script
so whats the prob with the script

PHP Code:

//#CLIENTSIDE
function onCreated(){

setTimer(.05);
}
function 
onTimeout(){
hideimgs(0,200);
  for (
i=0this.hps.size(); i++) {
    
showtext(i,this.hps[i][1],this.hps[i][2],"Arial","cb",this.hps[i][0]);
    if (
this.hps[i][0] < 0changeimgcolors(i,1,0,0,1);
     else 
changeimgcolors(i,0,1,0,1);
    
changeimgzoom(i,.8);
    
this.hps[i][2]-=.1;
    
this.hps[i][3]--;
    if (
this.hps[i][3] == 0) {
      
this.hps.delete(i);
    }
  }
  
  if (
client.hp clientr.hpmaxclient.hp clientr.hpmax;
  if (
player.hearts 0this.dead 1;
  if (
this.dead) {
    if (
player.hearts != 0) {
      
this.dead 0;
      
client.hp clientr.hpmax;
      
player.hearts 3;
    }
  }else if (
client.hp <= 0) {
    
player.hearts 0;
    
this.dead 1;
  }else if (
player.fullhearts == 20) {
    if (
player.hearts != 3) {
      
this.php = (player.hearts 3) * 2;
      
client.hp += int(this.php);
      
player.hearts 3;
      
this.hps.add({this.php,player.x+1.5,player.y-1,80});
    }
  }else 
serverwarp("login1");
  
  
setTimer(.05);
}
function 
onPlayerenters(){
this.hps NULL;



excaliber7388 07-20-2008 06:27 AM

Any chance that punch script has a for loop? Correct me if I'm wrong, but having the normal variables of i (as opposed to this.i), will change the player's value for i. If the punch script uses a variable by the same name, you'll run into problems.
Change all instances of "i" to "this.i" and see if that works. You have to remember that the player stores all the variables, not the individual script, unless they're temporary (temp.) or specific to a set of brackets (this.) (that is how this. works, right?).
I haven't scripted in over a year, but I think that may be the problem.

zokemon 07-20-2008 07:41 AM

No Cali, that isn't the problem.
Try commenting out the entire script then narrowing down what is commented out till you discover what part of the script is causing the problem.

excaliber7388 07-20-2008 07:59 AM

Quote:

Originally Posted by zokemon (Post 1405683)
No Cali, that isn't the problem.
Try commenting out the entire script then narrowing down what is commented out till you discover what part of the script is causing the problem.

Is it that you know the punch script does not use 'i', or is the i variable local to that block, and I was wrong in my thinking?

cbk1994 07-20-2008 08:03 AM

Quote:

Originally Posted by excaliber7388 (Post 1405685)
Is it that you know the punch script does not use 'i', or is the i variable local to that block, and I was wrong in my thinking?

'i' should be declared at least once; something like this:

PHP Code:

for ( temp.foo )
{
  echo( 
);


is perfectly acceptable.

Like Zero said, try to debug it.

xXziroXx 07-20-2008 02:52 PM

Quote:

Originally Posted by cbk1994 (Post 1405686)
'i' should be declared at least once; something like this:

PHP Code:

for ( temp.foo )
{
  echo( 
);


is perfectly acceptable.

I've encountered several occasions where declaring the variable only once, and then reading it without a temp. header, simply do not work. It's a lazy way to do things, you should always be arsed to type out the whole thing.

zokemon 07-20-2008 08:18 PM

Quote:

Originally Posted by excaliber7388 (Post 1405685)
Is it that you know the punch script does not use 'i', or is the i variable local to that block, and I was wrong in my thinking?

Well it is good practice to use a header when defining a temporary variable in a function for the first time but unless the scripter of the punch script was really bad and used global variables for storing data (such as i instead of this.i) it wouldn't matter.

I don't see why someone would use i to store something like that though.

cbk1994 07-20-2008 08:20 PM

Quote:

Originally Posted by xXziroXx (Post 1405744)
I've encountered several occasions where declaring the variable only once, and then reading it without a temp. header, simply do not work. It's a lazy way to do things, you should always be arsed to type out the whole thing.

I disagree; I've never had problems with this. I don't see it as lazy; I actually don't like reading code where the 'temp' prefix is included over and over.


All times are GMT +2. The time now is 06:03 AM.

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