Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Chat System (https://forums.graalonline.com/forums/showthread.php?t=134265402)

Gunderak 12-24-2011 06:53 AM

Chat System
 
2 Attachment(s)
New and improved!
It allows you to press C and chat to other players on the server.
Add whoever's account into this.admins to make their name red.
Script is attached, simply ulpoad as a weapon and add to whomever you wish to have it.

Features
1. Click W to toggle a list of online players using chat, Press R to refresh the list.
2. Automatically detects HTML and disallows it.

To come
A right click on player with ban, kick, etc etc for admins.

-Enjoy

ffcmike 12-24-2011 07:02 AM

You're still making the basic mistake of having multiple instances of if(condition){} occurring when a previous condition has already been established as true.

It's also a bad idea to store staff accounts clientside this way as it can be modified via a memory editor, this really needs to be validated serverside.

I'm sure you've already been told about these 2 issues about a dozen times already.

cbk1994 12-24-2011 07:09 AM

You should remove the HTML serverside, anyone could still easily send HTML simply by disabling that check on clientside. Same thing goes for admins. The receiver should determine if the sender is an admin. The sender should never tell other people it's an admin since it's not trusted.

Why are you using four triggers to get the online list (which, by the way, is available clientside in allplayers)? Two triggers would work fine. You're also relying on the this. variable to remain unchanged in between the triggers which in this case won't cause problems but is a little naive.

You shouldn't treat booleans as integers (e.g. line 32), this is confusing to the reader although not really a performance issue.

Why is the player sending their own name with the send message trigger? This is easily faked. I could make it look like any player was sending a message if I wanted to.

On line 138 you forgot to close the <font> tag for the admin color and for the message. If you closed the admin color one, you wouldn't need to specify the color as white. This should have hinted you in on the error.

You should name related GUI controls with a similar prefix (e.g. everything should start with Chat_). You're also using a weird mixture of width, height, extent, and clientextent. You should always use client, and pick either extent or width/height and stick with it throughout the script. I prefer width/height but others prefer extent.

Why can't I send a message starting with a space? Shouldn't it just trim my message for me?

That's all I noticed on first read through. Please stop posting in the code gallery until you can produce scripts without blatant errors like these ones. They're bad examples for others. I've brought this up before.

Gunderak 12-24-2011 07:23 AM

Quote:

On line 138 you forgot to close the <font> tag for the admin color and for the message. If you closed the admin color one, you wouldn't need to specify the color as white. This should have hinted you in on the error.
If I closed the font tag the text would become black, but I want it to be white.
Thus pointless to close it.
I will fix the account check now and re post.

Update
I have changed the script around.
Are there still problems with it anywhere?

cbk1994 12-24-2011 08:36 AM

Quote:

Originally Posted by Gunderak (Post 1679309)
If I closed the font tag the text would become black, but I want it to be white.
Thus pointless to close it.

It isn't pointless to close it. You're now writing not only bad GScript but also bad HTML—congratulations.

Yes, most of the issues I'd originally pointed out still exist, like not allowing text starting with a space rather than just trimming it, the use of four triggers when none (at most, two) are needed, the misuse of integers, the mixing of extent/width/height/clientextent, the bad naming of GUI controls, etc.

I wouldn't be so tough on you if you stopped ignoring advice. This does not belong in the code gallery.

Gunderak 12-24-2011 08:39 AM

I'm not ignoring advice, I am trying to correct the errors.

ffcmike 12-24-2011 08:52 AM

Imagine you were to lose something, for example a pair of keys.
Now imagine you spend a couple of minutes searching for them, then you manage to find them. Would you then continue searching for them after you've found them?
Ofcourse not, that would be absurd.

Checking conditions after a condition has already been established may not have any real effect on performance in this instance, but it makes just as little sense.

Gunderak 12-24-2011 09:42 AM

Are you talking about the serverside and clientside checks?
For triggering things?

ffcmike 12-24-2011 09:55 AM

Quote:

Originally Posted by Gunderak (Post 1679320)
Are you talking about the serverside and clientside checks?
For triggering things?

I'm talking about:

PHP Code:

if(params[0] == something){

}

if(
params[0] == somethingelse){



Which occurs both serverside and clientside.
If the parameter is something, there is then no need to check if it is somethingelse. You should either use a switch statement or a return; within the bracket.

Gunderak 12-24-2011 11:51 AM

Ah ok, I will make it a switch / case then.
Thanks.

Crow 12-24-2011 01:28 PM

Quote:

Originally Posted by Gunderak (Post 1679324)
Ah ok, I will make it a switch / case then.
Thanks.

You can also use elseif.

Gunderak 12-24-2011 02:06 PM

Whats the difference between if and elseif o.o
They do the exact same thing..

callimuc 12-24-2011 05:38 PM

Quote:

Originally Posted by Gunderak (Post 1679343)
Whats the difference between if and elseif o.o
They do the exact same thing..

PHP Code:

if (YouAreHere) {
  
thanStartFunction();
}
else if (
YouAreNotHere) {
  
thanDontStartFunction();



Like talking english.

cbk1994 12-24-2011 05:48 PM

Quote:

Originally Posted by Gunderak (Post 1679343)
Whats the difference between if and elseif o.o
They do the exact same thing..

It makes it clear the previous condition was not true, e.g.

PHP Code:

if (5) {
 
// a is greater than 5
} else if (5) {
 
// a is less than 5
} else {
  
// a must b 5


You should use them when appropriate as they make code easier to read.

Hezzy002 12-24-2011 06:47 PM

Quote:

Originally Posted by cbk1994 (Post 1679356)
It makes it clear the previous condition was not true, e.g.

PHP Code:

if (5) {
 
// a is greater than 5
} else if (5) {
 
// a is less than 5
} else {
  
// a must b 5


You should use them when appropriate as they make code easier to read.

There actually is a difference, though, that you forgot to note.

PHP Code:

foo true;
bar true;

if (
foo) {
  
//Hit one
} else if (bar) {
  
//Hit two


Only the first conditional will hit.

PHP Code:

foo true;
bar true;

if (
foo) {
  
//Hit one
}
if (
bar) {
  
//Hit two


Both will hit.

But seriously, why are we wasting our time on this kid? He clearly has no desire to learn and is stubborn as ****, is he worth any of our time? When I had people teaching me, I literally salivated over the **** they were saying, because I knew they were better than me and they knew what they were doing. Now the table's have turned and I hate seeing idiots like this.

Emera 12-24-2011 07:25 PM

I think the design of the system is really quite nice! Good work with the design.

Gunderak 12-25-2011 08:39 AM

@Emera, Thanks, at least I have done something right o_o

@Hezzy Lol, Kid? I'm 23.
And I'm not an idiot, I am just simply asking why it is necessary to do it so I can learn more.

cbk1994 12-25-2011 10:03 AM

Quote:

Originally Posted by Gunderak (Post 1679421)
@Hezzy Lol, Kid? I'm 23.
And I'm not an idiot, I am just simply asking why it is necessary to do it so I can learn more.

You're not an idiot, you're just stupid. You seem to think you can become a better scripter by ignoring advice. Merry Christmas.

Gunderak 12-25-2011 11:08 AM

I have to admin you just owned me....
But regardless, I am trying to become better but all I did was ask why it's better to do it that way so that I know, I'm trying to learn as much as I can.
And a Merry Christmas and a Happy New Year to you too.

Tolnaftate2004 12-25-2011 07:54 PM

Quote:

Originally Posted by cbk1994 (Post 1679356)
It makes it clear the previous condition was not true...

Quote:

Originally Posted by Hezzy002 (Post 1679359)
There actually is a difference, though, that you forgot to note.

Most importantly, an if followed by an else will result on a jump instruction, which saves you the instructions for symbol lookup and relation test, etc. by slipping them => faster code.

Gunderak 12-27-2011 02:48 AM

Ah, have been playing around with this.
It goes a little buggy with an if statement after an else.
So would it be better to do an else if statement in this situation?


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

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