Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-24-2011, 06:53 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Chat System

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
Attached Thumbnails
Click image for larger version

Name:	screenshot.png
Views:	359
Size:	20.6 KB
ID:	54115  
Attached Files
File Type: txt script.txt (4.9 KB, 359 views)
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 12-24-2011 at 07:35 AM..
Reply With Quote
  #2  
Old 12-24-2011, 07:02 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.
Reply With Quote
  #3  
Old 12-24-2011, 07:09 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #4  
Old 12-24-2011, 07:23 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 12-24-2011 at 07:36 AM..
Reply With Quote
  #5  
Old 12-24-2011, 08:36 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Reply With Quote
  #6  
Old 12-24-2011, 08:39 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
I'm not ignoring advice, I am trying to correct the errors.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #7  
Old 12-24-2011, 08:52 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.
Reply With Quote
  #8  
Old 12-24-2011, 09:42 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Are you talking about the serverside and clientside checks?
For triggering things?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #9  
Old 12-24-2011, 09:55 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.
Reply With Quote
  #10  
Old 12-24-2011, 11:51 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Ah ok, I will make it a switch / case then.
Thanks.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #11  
Old 12-24-2011, 01:28 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Gunderak View Post
Ah ok, I will make it a switch / case then.
Thanks.
You can also use elseif.
Reply With Quote
  #12  
Old 12-24-2011, 02:06 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Whats the difference between if and elseif o.o
They do the exact same thing..
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #13  
Old 12-24-2011, 05:38 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Gunderak View Post
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.
__________________
MEEP!
Reply With Quote
  #14  
Old 12-24-2011, 05:48 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Reply With Quote
  #15  
Old 12-24-2011, 06:47 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #16  
Old 12-24-2011, 07:25 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
I think the design of the system is really quite nice! Good work with the design.
__________________
Reply With Quote
  #17  
Old 12-25-2011, 08:39 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
@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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #18  
Old 12-25-2011, 10:03 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
@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.
__________________
Reply With Quote
  #19  
Old 12-25-2011, 11:08 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #20  
Old 12-25-2011, 07:54 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by cbk1994 View Post
It makes it clear the previous condition was not true...
Quote:
Originally Posted by Hezzy002 View Post
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 12-26-2011 at 01:39 AM..
Reply With Quote
  #21  
Old 12-27-2011, 02:48 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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