PDA

View Full Version : Problem with messages


contiga
02-24-2007, 02:05 PM
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.

function onActionServerSide() {
for ( i: allplayers)
i.triggerClient( "gui", "*Messages", params[ 0], 5, params[ 1]);
}

//#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", name, player.account, player.chat.substring( 5));
if ( player.chat.starts( "/sys"))
triggerServer( "gui", name, "System", player.chat.substring( 5));
if ( player.chat.starts( "/adm"))
triggerServer( "gui", name, "Admin", player.chat.substring( 5));
}

function onActionClientSide()
newMessage( params[ 0], params[ 1], params[ 2]);

function updateList() {
hideImgs( 200, 400);
cancelEvents( "delmessage");

if ( this.msgs.size() == NULL) {
this.lastdeltime = NULL;
return "";
}

this.linestaken = NULL;
this.shortesttime = 50;
this.destroylist = "";
this.laststart = timevar2;

for ( ind = 0; ind < this.msgs.size(); ind ++) {
this.msgs[ ind][ 1] = this.msgs[ ind][ 1] - this.lastdeltime;
this.linestakenbefore = this.linestaken;
this.cmsgt = this.msgs[ ind][ 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.msgs[ ind][ 2];
this.cmsgp = 0;

for ( i: this.cmsg) {

with ( findImg( 201 + this.linestaken)) {
text = i;
x = 32 + ( ( thiso.cmsg.index( i) < thiso.cmsg.size() - 1) ? 16 : 0);
y = screenheight - 56 - ( thiso.linestaken * 18);
shadowoffset = { - 1, + 1};
shadowcolor = { 0, 0, 0};
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_x, this.poly_y, this.poly_x + this.poly_w, this.poly_y, this.poly_x + this.poly_w, this.poly_y + this.poly_h, this.poly_x, this.poly_y + this.poly_h};

if ( this.msgs[ ind][ 0] == "System")
this.poly_c = { 1, 0.8, 0};
else if ( this.msgs[ ind][ 0] == "Admin")
this.poly_c = { 1, 0, 0};
else
this.poly_c = { 0.2, 1, 0.2};

with ( findImg( 300 + ind)) {
polygon = thiso.poly_a;
alpha = ( ind % 2 == 1) ? 0.5 : 0.6;
green = thiso.poly_c[ 1];
blue = thiso.poly_c[ 2];
red = thiso.poly_c[ 0];
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_x, this.poly_y, this.poly_x + this.poly_w, this.poly_y, this.poly_x + this.poly_w, this.poly_y + this.poly_h, this.poly_x, this.poly_y + this.poly_h};
with ( findImg( 200)) {
polygon = thiso.poly_a;
alpha = 0.8;
red = green = blue = 0;
layer = 4;
mode = 1;
}
scheduleEvent( this.shortesttime, "DelMessage", this.shortesttime);
}

function onDelMessage( dt) {
for ( dmsg: this.destroylist)
this.msgs.delete( dmsg - this.destroylist.index( dmsg));

if ( this.msgs.size() == NULL) this.lastdeltime = NULL;
else this.lastdeltime = dt;

updateList();
}

public function newMessage( sender, time, msg) {
this.lastdeltime = int( timevar2 - this.laststart);

if ( this.lastdeltime > 50) this.msgs = NULL;
if ( this.msgs.size() == NULL) this.lastdeltime = NULL;

position = this.msgs.size() + 1;
this.msgs.insert( 0, { sender, time, turnAround( wraptext2( 300, 0.8, " ", "@[email protected]@*" @ sender @ ": " @ msg))});

updateList();
}

function turnAround( cmsg) {
temp.msg = "";
for ( temp.c: cmsg)
temp.msg.insert( 0, temp.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:


for (i=this.destroylist.size()-1; i>=0; i--)
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
...


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
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
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
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
That's what it is doing.. x_x

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