Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GANI scripts in attributes; updating (https://forums.graalonline.com/forums/showthread.php?t=134257573)

cbk1994 01-07-2010 03:39 PM

GANI scripts in attributes; updating
 
I'm having trouble with GANI scripts used in player attributes to show an HP bar. It works for the first display, but then doesn't always update.

This is the code (serverside):

PHP Code:

this.attr[3] = "era_hpbar.gani," @ (this.health this.initialHealth); 

and this is the GANI script:

PHP Code:

SCRIPT
function onCreated() {
  
showBar(params[0]);
}

function 
onPlayerEnters() {
  
onCreated();
}

function 
showBar(percent) {
  
with (findimg(200)) {
    
image "erai_hpbar.png";
    
    
this.0.25;
    
this.1.5;
    
layer 1;
    
    
attachtoowner true;
  }
  
  
changeImgPart(200004111);
  
  
with (findimg(201)) {
    
image "erai_hpbar.png";
    
    
this.0.25;
    
this.1.5;
    
    
layer 2;
    
    
attachtoowner true;
  }
  
  
changeImgPart(201012max(141 percent), 11);
}
SCRIPTEND 

The bar will always show correctly if I try to display it when the bar isn't already showing, but if it is already showing, it won't update.

Fulg0reSama 01-07-2010 03:49 PM

I was thinking about how to fix this because i face a similar problem.

i was thinking like a timeout to readd while a onplayerhurt function would remove the attribute setting for the duration than add back afterwords Though im not sure if that could even work. Because i have a smaller project that requires a image to stay up at all times. Hope this gives you a lead onto a fix perhaps. If so give me the method and maybe i can work my own way around my problem :P

But of course im talking about how mine works... Good luck to your problem :(

cbk1994 01-07-2010 03:52 PM

What I ended up doing is just rotating between two attributes (2 and 3) instead of sticking with one, which lets it always update, but it's still a pain in the ass, and I think there's a way to make it work anyway :(

Fulg0reSama 01-07-2010 03:59 PM

not a bad loophole for this problem. good job. Hopefully someone has an answer to fixing this without having to use 2 attributes.

DustyPorViva 01-07-2010 04:00 PM

Sadly I've tried to force it to update, even by clearing the attr and setting it again, but to no avail. So I end up having to resort to using another attr to store the data, which sucks.

I've made a bug report on this update problem, but no response...

Crow 01-07-2010 04:02 PM

Quote:

Originally Posted by DustyPorViva (Post 1548813)
Sadly I've tried to force it to update, even by clearing the attr and setting it again, but to no avail. So I end up having to resort to using another attr to store the data, which sucks.

I've made a bug report on this update problem, but no response...

Did you put a short sleep after clearing the attribute and before setting it again? As far as I remember, that did the trick before for me.

DustyPorViva 01-07-2010 04:03 PM

Quote:

Originally Posted by Crow (Post 1548814)
Did you put a short sleep after clearing the attribute and before setting it again? As far as I remember, that did the trick before for me.

Can't put a sleep in timeouts :)

Crow 01-07-2010 04:15 PM

Quote:

Originally Posted by DustyPorViva (Post 1548815)
Can't put a sleep in timeouts :)

scheduleEvent()

Fulg0reSama 01-07-2010 04:16 PM

Interesting!

btw crow +rep just for your whole signature when I can do it again

DustyPorViva 01-07-2010 04:27 PM

Quote:

Originally Posted by Crow (Post 1548818)
scheduleEvent()

Keep forgetting about that! I really should utilize it more often... however I wish this bug was just crushed instead. Having a gani that's supposed to update constantly always running behind because we have to delay it before it updates isn't very ideal.

Chompy 01-07-2010 04:49 PM

Quote:

Originally Posted by DustyPorViva (Post 1548815)
Can't put a sleep in timeouts :)

You can use sleep() as long as you restart the event (timeout = #; || setTimer()) (Which you should usually do at the end of the timeout event)

DustyPorViva 01-07-2010 04:53 PM

Quote:

Originally Posted by Chompy (Post 1548825)
You can use sleep() as long as you restart the event (timeout = #; || setTimer()) (Which you should usually do at the end of the timeout event)

Not in a way that's healthy for the script, though. From my experience the sleep will function like a return, breaking everything after it, even if you reset the timeout.

xXziroXx 01-07-2010 05:48 PM

http://forums.graalonline.com/forums...ad.php?t=72413

DustyPorViva 01-07-2010 05:50 PM

Quote:

Originally Posted by xXziroXx (Post 1548832)

Indeed, but it's a bit silly to have one piece of functionality, like a health bar, rely on two attr's to work. I mean it's really the only way for it to function right now, but this needs to be addressed because it makes attr gani parameters pretty useless.

xXziroXx 01-07-2010 05:53 PM

Quote:

Originally Posted by DustyPorViva (Post 1548833)
Indeed, but it's a bit silly to have one piece of functionality, like a health bar, rely on two attr's to work. I mean it's really the only way for it to function right now, but this needs to be addressed because it makes attr gani parameters pretty useless.

I think I linked the wrong thing, meant to link a reply in the thread:

http://forums.graalonline.com/forums...66&postcount=5

Chompy 01-07-2010 07:18 PM

Quote:

Originally Posted by DustyPorViva (Post 1548826)
Not in a way that's healthy for the script, though. From my experience the sleep will function like a return, breaking everything after it, even if you reset the timeout.

Sleep() should not return and break everything after. Sleep() will freeze/pause the script for the given time, and then continue. :p


Also..
Quote:

Originally Posted by DustyPorViva (Post 1548815)
Can't put a sleep in timeouts :)

that is like saying you can't put sleep() in any loops (timeout, scheduleevent, while, for) ;D

PHP Code:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
setTimer(1);
}

function 
onTimeout() {
  echo(
this.var1);
  
sleep(5);
  echo(
this.var2);
  
setTimer(1);
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
scheduleEvent(1"Timeout2"0);
}

function 
onTimeout2() {
  echo(
this.var1);
  
sleep(5);
  echo(
this.var2);
  
scheduleEvent(5"Timeout2"0);
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
  
this.loop = function() {
    echo(
this.var1);
    
sleep(5);
    echo(
this.var2);
    
sleep(1);
    
this.loop();
  };
  
  
this.loop();
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
  while(!
waitfor(this"timeout"1)) {
    echo(
this.var1);
    
sleep(5);
    echo(
this.var2);
  }



Immolate 01-07-2010 07:44 PM

Quote:

Originally Posted by Chompy (Post 1548847)
Sleep() will not return and break everything after. Sleep() will freeze/pause the script for the given time, and then continue. :p


Also..


that is like saying you can't put sleep() in any loops (timeout, scheduleevent, while, for) ;D

PHP Code:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
setTimer(1);
}

function 
onTimeout() {
  echo(
this.var1);
  
sleep(5);
  echo(
this.var2);
  
setTimer(1);
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
scheduleEvent(1"Timeout2"0);
}

function 
onTimeout2() {
  echo(
this.var1);
  
sleep(5);
  echo(
this.var2);
  
scheduleEvent(5"Timeout2"0);
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
  
this.loop = function() {
    echo(
this.var1);
    
sleep(5);
    echo(
this.var2);
    
sleep(1);
    
this.loop();
  };
  
  
this.loop();
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
  while(!
waitfor(this"timeout"1)) {
    echo(
this.var1);
    
sleep(5);
    echo(
this.var2);
  }



When I used sleep() in a while loop, it broke :confused:.

Chompy 01-07-2010 07:53 PM

Quote:

Originally Posted by Immolate (Post 1548852)
When I used sleep() in a while loop, it broke :confused:.

Got an example snippet/script?

Immolate 01-07-2010 07:57 PM

Quote:

Originally Posted by Chompy (Post 1548858)
Got an example snippet/script?

Not anymore. I used a different method and my RC has been revoked on that server. I remember it breaking when sleep() was used though. Not sure if it's totally relevent anymore though, since this was about 5 months ago.

DustyPorViva 01-07-2010 10:52 PM

Quote:

Originally Posted by Chompy (Post 1548847)
that is like saying you can't put sleep() in any loops (timeout, scheduleevent, while, for) ;D

Not really, for() and while() loops don't have to be constantly called like a timeout.

Chompy 01-07-2010 11:19 PM

Quote:

Originally Posted by DustyPorViva (Post 1548899)
Not really, for() and while() loops don't have to be constantly called like a timeout.

The timeout event doesn't have to be called constantly either :p

The point now though, is that sleep() shouldn't break the script like you guys are explaining it, if it does.


All times are GMT +2. The time now is 04:53 PM.

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