Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Troubles with gani scripts (https://forums.graalonline.com/forums/showthread.php?t=78539)

coreys 01-31-2008 05:59 AM

Troubles with gani scripts
 
I'm using gani scripts for the display heart and nick/chat display on Maloria, but I'm running into trouble. For one thing, they don't always show up for everyone...sometimes they do, sometimes they don't, for no apparent reason. They also don't always work in the GMAP, but, like the other problem, sometimes they do.

It's all very frustrating, and I'm not entirely experienced with gani scripts, so if anyone has an idea, please help. D:

napo_p2p 01-31-2008 06:07 AM

I had pretty much the same problem a while back. It had to do with image objects getting destroyed. Hell Raven helped me out with it. I'm not sure if it applies in your case (you didn't provide a script :P), but here's a link to that thread:

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

coreys 01-31-2008 07:18 AM

Well, it's not a problem with playerenters, since I'm not using that. Most of the scripts aren't entirely mine, but rather old maloria script, but I edited them.

The Heart display script:
PHP Code:

function onCreated() {
  
showimg(200"mal_heartanim.gif", (player.0.5)%64, (player.2)%64);
  
setTimer(0.05);
}

function 
onTimeout() {
  
findimg(200).player.0.5;
  
findimg(200).player.2;

  if (
player.attr[8] == NULL) {
    
temp.healthcheck 0;

    
findimg(100).player.0.5;
    
findimg(100).player.2;
  
    
temp.healthcheck player.attr[4] * 100;

    if (
temp.healthcheck in |96100|) findimg(200).red 0.1;
    else if (
temp.healthcheck in |9195|) findimg(200).red 0.2;
    else if (
temp.healthcheck in |8690|) findimg(200).red 0.3;
    else if (
temp.healthcheck in |8185|) findimg(200).red 0.4;
    else if (
temp.healthcheck in |7680|) findimg(200).red 0.5;
    else if (
temp.healthcheck in |7175|) findimg(200).red 0.6;
    else if (
temp.healthcheck in |6670|) findimg(200).red 0.7;
    else if (
temp.healthcheck in |6165|) findimg(200).red 0.8;
    else if (
temp.healthcheck in |5660|) findimg(200).red 0.9;
    else if (
temp.healthcheck in |5155|) findimg(200).red 1;
    else if (
temp.healthcheck in |4650|) findimg(200).green 0.9;
    else if (
temp.healthcheck in |4145|) findimg(200).green 0.8;
    else if (
temp.healthcheck in |3640|) findimg(200).green 0.7;
    else if (
temp.healthcheck in |3135|) findimg(200).green 0.6;
    else if (
temp.healthcheck in |2630|) findimg(200).green 0.5;
    else if (
temp.healthcheck in |2125|) findimg(200).green 0.4;
    else if (
temp.healthcheck in |1620|) findimg(200).green 0.3;
    else if (
temp.healthcheck in |1115|) findimg(200).green 0.2;
    else if (
temp.healthcheck in |610|) findimg(200).green 0.1;
    else if (
temp.healthcheck in |15|) findimg(200).green 0;
  }
  else if (
player.attr[8] == "black") {
    
with (findimg(200)) {
      
mode red green blue 0;
    }
  }
  else if (
player.attr[8] == "white") {
    
with (findimg(200)) {
      
mode red green blue 1;
    }
  }
    
  
  
setTimer(0.05);


player.attr[4] is hp/maxhp (ignore the part with player.attr[8], I'm probably gonna remove it)

Here's the nickname display script:
PHP Code:

function onCreated() onTimeOut();
function 
onTimeOut() {
  if (!
clientr.stealth) {
    
temp.nick player.attr[10].tokenize("(");
    
temp.width1 = (temp.nick[0].length()*6)/16;
    
temp.width2 = (player.attr[11].length()*6)/16;
    
showtext(200player.x+1.5-(temp.width1/2), player.y+3"Verdana""b"temp.nick[0]);
    
changeimgcolors(200111.85);
    
changeimgzoom(200.6);
    
showtext(201player.x+1.5-(temp.width2/2), player.y+3.75"Verdana""b"player.attr[11]);
    
changeimgcolors(201111.85);
    
changeimgzoom(201.6);
  }
  else 
hideimgs(200201);
  
setTimer(0.05);


player.attr[10] is the players nickname

And then this is the chat display script. (It's quite messy, the guy who originally made it wasn't the best scripter)
PHP Code:

function onPlayerEnters() Init();
function 
onTimeOut() Init();
function 
Init() {
  if (
player.chat.length() > 0) {
    if(
this.mode != 1)
      
this.mode=1;
    if(
this.char != player.attr[16].length()) {
      
this.char player.attr[16].length();
      
hideimgs(200,400);
    }
    if(
this.text != player.attr[16] || this.chatx != (player.x) ||this.chaty != (player.y+2) || this.chatz != (player.z+2.5)) {
      
this.text player.attr[16];
      
temp.tokens wraptext(56,NULL,player.chat);
      
this.chatx player.x;
      
this.chaty player.y+2;
      
this.chatz player.z+2.5;
      for(
i=0;i<temp.tokens.size();i++) {
    
temp.width = (temp.tokens[i].length()*4)/16;
        
showtext2(200+i,this.chatx-(temp.width/2),this.chaty,this.chatz+(temp.tokens.size()-1)-i,"Comic Sans","b",temp.tokens[i]);
        
//Temporary color
        
changeimgcolors(200+i,1,1,1,1);
        
changeimgzoom(200+i,client.textsize);
        
findImg(200+i).layer++;
        
showtext2(300+i,this.chatx+.2-(temp.width/2),this.chaty+.2,this.chatz+(temp.tokens.size()-1)-i,"Comic Sans","b",temp.tokens[i]);
        
changeimgcolors(300+i,0,0,0,.5);
        
changeimgzoom(300+i,client.textsize);
      }
    }
  }
  else {
    if(
this.mode == 1) {
      
this.mode 0;
      
hideimgs(200,400);
    }
  }
  
setTimer(0.05);


I do, however, use onPlayerEnters() in the main system script. I do something like this:
PHP Code:

player.attr[7] = "";
player.attr[7] = "ganiname.gani"

To reset the gani script.

zokemon 01-31-2008 08:02 AM

You should be using onPlayerEnters, not onCreated. Gani scripts don't function very well with onCreated and onPlayerEnters is only called when the player seeing the gani first sees it for that instance, not when you actually enter a level.

Also, you should check for every player what their attrs are.

Like if I was doing it and was using you as a test subject, in a clientside test npc I would put:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
player.chat findplayer("zokemon").attr[2]; // (2 as an example)


I would see if both me and you had the same result in our chats. Then I would just replace zokemon with coreys and again check both of our chat's. Kinda hard to do that when you have chat disabled though so maybe a trigger serverside and an echo(account @ ": " @ result);

coreys 01-31-2008 04:35 PM

Well, I can always enable chat to test that, but also I have another problem. The function textwidth() doesn't work in gani scripts for some reason, and...it's a bit of a problem. I need the width of the text to properly center it. Is there some other way to accurately get the text width?

Oh, also, in the Heart Display gani it's showing an animated heart above the player. But for some reason, under the animation, it shows an un-animated version of that heart (the first frame of it, I guess)

Crow 01-31-2008 05:00 PM

Quote:

Originally Posted by coreys (Post 1372898)
Is there some other way to accurately get the text width?

wraptext2() ?

coreys 01-31-2008 05:54 PM

wraptext and wraptext2 don't get the width.

Crow 01-31-2008 06:03 PM

Well, wraptext2 works with the width set in pixels, so you could maybe get what you want with it.

Chompy 01-31-2008 06:05 PM

what you need is gettextwidth() instead of textwidth() ^^

zokemon 01-31-2008 08:19 PM

Quote:

Originally Posted by Chompy (Post 1372913)
what you need is gettextwidth() instead of textwidth() ^^

Exactly. textwidth is from GS1 and thus does not use quotes for the string within it (just like most gs1 string related commands).

If you try to do textwidth(this.chat, params) (don't know the placement of the arguements) you would simply get 9 all the time :).

coreys 01-31-2008 08:46 PM

Actually it was returning 0. I just didn't work at all. lol
But yeah, thanks Chompy!

Now to get that display heart to work right. >.<
It disappears whenever you go into a different level or whenever the WNPC that sets the player.attr[] for the gani is updated, or sometimes just not at all.

zokemon 01-31-2008 10:08 PM

Did you use onPlayerEnters like I said?

coreys 01-31-2008 10:30 PM

Yes, I did.

Crow 01-31-2008 10:47 PM

Try something like this:

PHP Code:

function onCreated()
  
onPlayerEnters();
function 
onPlayerEnters()
  
functionThatLeadsToCoreScript(); 

Doing that in all my gani scripts.

zokemon 01-31-2008 11:53 PM

Quote:

Originally Posted by Crow (Post 1372959)
Try something like this:

PHP Code:

function onCreated()
  
onPlayerEnters();
function 
onPlayerEnters()
  
functionThatLeadsToCoreScript(); 

Doing that in all my gani scripts.

Like I said, onCreated is pointless in gani scripts. Just don't use it.

coreys 02-02-2008 08:22 AM

Blah, I'm still having trouble with peoples names and display hearts not always showing up and problems with GMAPs.

Crow 02-02-2008 01:28 PM

Quote:

Originally Posted by zokemon (Post 1372970)
Like I said, onCreated is pointless in gani scripts. Just don't use it.

That was actually the tiny part that got my gani scripts to work, so I have no idea what you are talking about.

coreys 02-07-2008 04:40 PM

Yeah, I've figured that the nick display gani stops showing when you go into the overworld, even if you come back into another level.
This is what I have for that script:
PHP Code:

function onPlayerEnters() {
  
this.nick "";
  
this.guild "";
  
onTimeOut();
}
function 
onTimeOut() {
  if (!
clientr.stealth) {
    if (
this.nick != player.attr[10] || this.guild != player.attr[11])
      
updateNick();
    for (
i=0i<4i++) {
      
changeimgcolors(200+iplayer.attr[17], player.attr[18], player.attr[19], .8);
      
changeimgzoom(200+ithis.size);
    }
    
changeimgcolors(202000.3);
    
changeimgcolors(203000.3);
  }
  else 
hideimgs(200,203);
  if (
this.font != player.attr[21] || this.style != player.attr[22] || this.size != player.attr[23])
    
updateNick();
  
setTimer(0.05);
}
function 
updateNick() {
  
hideimgs(200,203);
  
this.font player.attr[21];
  
this.style player.attr[22];
  
this.size player.attr[23];
  
this.nick player.attr[10];
  
this.guild player.attr[11];
  
temp.this.nick.tokenize("(");
  
temp.width1 gettextwidth(this.sizethis.fontthis.styletemp.n[0])/16;
  
temp.width2 gettextwidth(this.sizethis.fontthis.stylethis.guild)/16;
  
showtext(200player.x+1.5-(temp.width1/2), player.y+3this.fontthis.styletemp.n[0]);
  
showtext(201player.x+1.5-(temp.width2/2), player.y+3.75this.fontthis.stylethis.guild);
  
showtext(202player.x+1.5+(1/8)-(temp.width1/2), player.y+3+(1/8), this.fontthis.styletemp.n[0]);
  
showtext(203player.x+1.5+(1/8)-(temp.width2/2), player.y+3.75+(1/8), this.fontthis.stylethis.guild);
  for (
i=0i<4i++) {
    
changeimgcolors(200+iplayer.attr[17], player.attr[18], player.attr[19], .85);
    
changeimgzoom(200+ithis.size);
    
findImg(200+i).attachtoowner true;
  }
  
changeimgcolors(202000.85);
  
changeimgcolors(203000.85);
  
findImg(200).layer++;
  
findImg(201).layer++;


Also, my heart display keeps turning black at random times, and I can't really figure out why...
PHP Code:

function onCreated() {
  
showimg(200"mal_heartanim.gif", (player.0.5)%64, (player.2)%64);
  
setTimer(0.05);
}
function 
onPlayerEnters() {
  
showimg(200"mal_heartanim.gif", (player.0.5)%64, (player.2)%64);
  
setTimer(0.05);
}
function 
onTimeout() {
  
findimg(200).player.0.5;
  
findimg(200).player.2;

  
temp.healthcheck player.attr[4]*100;

  
findimg(200).player.0.5;
  
findimg(200).player.2;
  if (
temp.healthcheck in |96100|) temp.colors = {0,1};
  else if (
temp.healthcheck in |9195|) temp.colors = {.05,.95};
  else if (
temp.healthcheck in |8690|) temp.colors = {.1,.9};
  else if (
temp.healthcheck in |8185|) temp.colors = {.15,.85};
  else if (
temp.healthcheck in |7680|) temp.colors = {.2,.8};
  else if (
temp.healthcheck in |7175|) temp.colors = {.25,.75};
  else if (
temp.healthcheck in |6670|) temp.colors = {.3,.7};
  else if (
temp.healthcheck in |6165|) temp.colors = {.35,.65};
  else if (
temp.healthcheck in |5660|) temp.colors = {.4,.6};
  else if (
temp.healthcheck in |5155|) temp.colors = {.45,.55};
  else if (
temp.healthcheck in |4650|) temp.colors = {.5,.5};
  else if (
temp.healthcheck in |4145|) temp.colors = {.55,.45};
  else if (
temp.healthcheck in |3640|) temp.colors = {.6,.4};
  else if (
temp.healthcheck in |3135|) temp.colors = {.65,.35};
  else if (
temp.healthcheck in |2630|) temp.colors = {.7,.3};
  else if (
temp.healthcheck in |2125|) temp.colors = {.75,.25};
  else if (
temp.healthcheck in |1620|) temp.colors = {.8,.2};
  else if (
temp.healthcheck in |1115|) temp.colors = {.85,.15};
  else if (
temp.healthcheck in |610|) temp.colors = {.9,.1};
  else if (
temp.healthcheck in |15|) temp.colors = {.95,.05};
  
findImg(200).red temp.colors[0];
  
findImg(200).green temp.colors[1];
  
findImg(200).blue 0;
  
setTimer(0.05);




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

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