Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Problem with messages (https://forums.graalonline.com/forums/showthread.php?t=72432)

contiga 02-24-2007 02:05 PM

Problem with messages
 
NOTE: First of all, I'd like to say that no one is allowed to use this script for his/her own server, or a server he/she works on. I'm just showing this because I can't find a problem in it, but there is.

The problem: The first time I add a few messages, everything works perfect, but as soon as I use my (tempory) commands like; /msg <msg>, /adm <msg> and/or /sys <msg>, things go wrong.

What goes wrong?

The 5 between params[ 0] and params[ 1] in the serverside part (i.triggerClient ... line) stands for the seconds the message should show.
The first time I do a message, after all the other messages, which I added at onCreated() ..., are hidden (using '/msg' or any of the other commands) it still works fine. But when I wait one second after the first time, and then add another message, it SHOULD be like, the first message has 4 seconds left of showing, and the new message 5 seconds. But what happens? They both hide after 4 seconds. So yeah.. that pretty much "sucks" xD Especially if I wait 4 seconds and then add a new message, because then, they'll both hide after 1 second.

I hope anyone gets what I mean, and is able to help me.

PHP Code:

function onActionServerSide() {
  for ( 
iallplayers)
    
i.triggerClient"gui""*Messages"params0], 5params1]);
}

//#CLIENTSIDE
function onCreated() {

  
newMessage"System"10"Welcome to Bomy Islands!");
  
newMessage"contiga"6"*test 123 test*");
  
newMessage"Stefan"9"I'll come to G2k1 immediately, to script you guys a better bomypet!!!");
  
newMessage"Konidias"14"Lalaaalaaa :D");
  
newMessage"Admin"14"Testmsgg");
  
newMessage"contiga"15"Test");

  
this.lastdeltime this.shortesttime NULL;
  
this.laststart timevar2;
  
this.maxlines 16;
}

function 
onPlayerChats() { // just temp, to test
  
if ( player.chat.starts"/msg"))
    
triggerServer"gui"nameplayer.accountplayer.chat.substring5));
  if ( 
player.chat.starts"/sys"))
    
triggerServer"gui"name"System"player.chat.substring5));
  if ( 
player.chat.starts"/adm"))
    
triggerServer"gui"name"Admin"player.chat.substring5));
}

function 
onActionClientSide()
  
newMessageparams0], params1], params2]);

function 
updateList() {
  
hideImgs200400);
  
cancelEvents"delmessage");
  
  if ( 
this.msgs.size() == NULL) {
    
this.lastdeltime NULL;
    return 
"";
  }
  
  
this.linestaken NULL;
  
this.shortesttime 50;
  
this.destroylist "";
  
this.laststart timevar2;
  
  for ( 
ind 0ind this.msgs.size(); ind ++) {
    
this.msgsind][ 1] = this.msgsind][ 1] - this.lastdeltime;
    
this.linestakenbefore this.linestaken;
    
this.cmsgt this.msgsind][ 1];
    
    if ( 
this.cmsgt this.shortesttime) {
      
this.shortesttime this.cmsgt;
      
this.destroylist ind ",";
    }
    else if ( 
this.cmsgt == this.shortesttime)
      
this.destroylist @= ind ",";
      
    
this.cmsg this.msgsind][ 2];
    
this.cmsgp 0;
    
    for ( 
ithis.cmsg) {
    
      
with findImg201 this.linestaken)) {
        
text i;
        
32 + ( ( thiso.cmsg.indexi) < thiso.cmsg.size() - 1) ? 16 0);
        
screenheight 56 - ( thiso.linestaken 18);
        
shadowoffset = { - 1, + 1};
        
shadowcolor = { 000};
        
textshadow true;
        
font "Arial";
        
style "b";
        
zoom 0.8;
        
layer 6;
      }
      
      
this.linestaken ++;
      
this.cmsgp ++;
    }
    
    
this.poly_x 28;
    
this.poly_y screenheight 37 - ( ( this.linestakenbefore this.cmsgp) * 18);
    
this.poly_w 324;
    
this.poly_h thiso.cmsgp 18;
    
this.poly_a = { this.poly_xthis.poly_ythis.poly_x this.poly_wthis.poly_ythis.poly_x this.poly_wthis.poly_y this.poly_hthis.poly_xthis.poly_y this.poly_h};

    if ( 
this.msgsind][ 0] == "System"
      
this.poly_c = { 10.80};
    else if ( 
this.msgsind][ 0] == "Admin"
      
this.poly_c = { 100};
    else
      
this.poly_c = { 0.210.2};
      
    
with findImg300 ind)) {
      
polygon thiso.poly_a;
      
alpha = ( ind == 1) ? 0.5 0.6;
      
green thiso.poly_c1];
      
blue thiso.poly_c2];
      
red thiso.poly_c0]; 
      
layer 5;
      
mode 1;
    }
  }
  
  
this.poly_x 28;
  
this.poly_y screenheight 37 - ( ( this.linestakenbefore this.cmsgp) * 18);
  
this.poly_w 324;
  
this.poly_h this.linestaken 18;
  
this.poly_a = { this.poly_xthis.poly_ythis.poly_x this.poly_wthis.poly_ythis.poly_x this.poly_wthis.poly_y this.poly_hthis.poly_xthis.poly_y this.poly_h};
  
with findImg200)) {
    
polygon thiso.poly_a;
    
alpha 0.8;
    
red green blue 0
    
layer 4;
    
mode 1;
  }
  
scheduleEventthis.shortesttime"DelMessage"this.shortesttime);
}

function 
onDelMessagedt) {
  for ( 
dmsgthis.destroylist)
    
this.msgs.deletedmsg this.destroylist.indexdmsg));
  
  if ( 
this.msgs.size() == NULLthis.lastdeltime NULL;
  else 
this.lastdeltime dt;
  
  
updateList();
}

public function 
newMessagesendertimemsg) {
  
this.lastdeltime inttimevar2 this.laststart);
  
  if ( 
this.lastdeltime 50this.msgs NULL;
  if ( 
this.msgs.size() == NULLthis.lastdeltime NULL;
  
  
position this.msgs.size() + 1;
  
this.msgs.insert0, { sendertimeturnAroundwraptext23000.8" ""@Arial@b@*" sender ": " msg))});
  
  
updateList();
}

function 
turnAroundcmsg) {
  
temp.msg "";
  for ( 
temp.ccmsg)
    
temp.msg.insert0temp.c);
  return 
temp.msg;


Ps. I didn't style this script like I should style it yet, I just kept a lot of space to keep the script well-organized because of the errors in it.

Admins 02-24-2007 03:52 PM

I think onDelMessage( dt) is bugged, should be changed to:

PHP Code:

  for (i=this.destroylist.size()-1i>=0i--)
    
this.msgs.delete(this.destroylist[i]); 

Otherwise you delete the wrong indices. In my opinion the whole deletion stuff should be made simplier though, e.g. remember in this.msgs the abolute time until the message should exist (timevar2 + time) and put the deletion stuff into onTimeout() or similar (if you don't want a timeout then use scheduleevent which is calling scheduleevent again until all messages are vanished)

contiga 02-25-2007 04:09 PM

Quote:

Originally Posted by Stefan (Post 1281589)
...

Sorry but that did nothing "new". Anyone else, any idea?
Thanks tho, Stefan

Chandler 02-25-2007 04:24 PM

Do a check to see which images are being destroyed, and what time it's displaying for it to be destroyed. What does it report?

Admins 02-25-2007 07:02 PM

Quote:

Originally Posted by contiga (Post 1282036)
Sorry but that did nothing "new".

Well it shows the bug in your script, I am wondering for what other reason you have posted your problem.

contiga 02-26-2007 06:02 PM

Quote:

Originally Posted by Stefan (Post 1282083)
Well it shows the bug in your script, I am wondering for what other reason you have posted your problem.

It has to do with the timer I used (timevar stuff), the deleting function is fine, just the this.destroylist gets set wrong.. x-x

So yeah..?

contiga 03-05-2007 02:03 PM

*bump*

Kristi 03-05-2007 08:15 PM

What stefan says had merit. I do not know why you are shrugging him off.

Your delete system seems too complicated. I would just find out what message is supposed to be deleted next, and schedule an update event when its supposed to be deleted, saving the index thats supposed to be deleted next, and save the time to deletion. Then delete that message, and then the update would run, finding out when the shortest time is left again by subtracting how much time has passed since the last update, and schedule itsself to run an update again.

contiga 03-06-2007 05:02 PM

Quote:

Originally Posted by Kristi (Post 1285147)
Your delete system seems too complicated. I would just find out what message is supposed to be deleted next, and schedule an update event when its supposed to be deleted, saving the index thats supposed to be deleted next, and save the time to deletion. Then delete that message, and then the update would run, finding out when the shortest time is left again by subtracting how much time has passed since the last update, and schedule itsself to run an update again.

That's what it is doing.. x_x

zell12 03-06-2007 05:11 PM

Contiga, I think Stefan was on the right track, take more then ~10 minutes to utilize his advice.

Kristi 03-06-2007 05:48 PM

Quote:

Originally Posted by contiga (Post 1285546)
That's what it is doing.. x_x

Then it is obviously doing it wrong! Just rewrite it.


All times are GMT +2. The time now is 10:59 PM.

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