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 08-26-2011, 04:33 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
Server Flag Adder

I have finally completed my code! Thank you to everybody who contributed towards the completion of the code by helping me out on various threads I have created about the development of this tool.

The Tool
The Server Flag Adder is a tool for displaying all of the current server flags in a nice GUI menu. Within the menu, you have the option to add flags to the server without creating them through a script. It displays the flags you already have present on your server with a Text List control in a nice little interface. I myself like to use GUI's as much as I can as it makes whatever you are developing nice and tidy (if you design the GUI properly!)

To open the GUI, all the player has to do is chat "/flagadder". Obviously, you can change that command to whatever you prefer or even allow it to open after a certain key has been pressed.

CODE
PHP Code:
function onCreated() {
  
this.allowed = {
    
"McChucken""Other community name"
  
};
}
function 
onActionServerside() {
  if (
params[0] == "addflags")  { 
    if (
player.communityname in this.allowed) {
      
serverr.(@params[1]) = params[2];
    }  
  }
}

//#CLIENTSIDE
function addrowsys_Button1.onAction() {
  new 
GuiWindowCtrl("Extent_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
style $pref::Video::defaultguistyle;
    
clientextent "176,118";
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide true;
    
text "Add a flag";
    
517;
    
209;
    new 
GuiTextEditCtrl("Extent_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
7;
      
19;
    }
    new 
GuiTextEditCtrl("Extent_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
7;
      
59;
    }
    new 
GuiTextCtrl("Extent_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Flag Content";
      
width 73;
      
92;
      
58;
    }
    new 
GuiTextCtrl("Extent_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Title / Name";
      
width 69;
      
93;
      
18;
    }
    new 
GuiButtonCtrl("Extent_Button1") {
      
profile GuiBlueButtonProfile;
      
height 22;
      
text "Add Flag";
      
width 164;
      
6;
      
90;
    }
  }
}

function 
CreateGui() {
  new 
GuiWindowCtrl("addrowsys_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "367,238";
    
isexternal false;
    
style $pref::Video::defaultguistyle;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Server Flag Editor";
    
480;
    
84;
    new 
GuiControl("Border1") {
      
useownprofile true;
      
profile.border 0;
      
profile.opaque true;
      
profile.fillColor = {
        
163194212120
      
};
      
width 367;
      
height 238;
      
0;
      
0;
    }
    new 
GuiButtonCtrl("addrowsys_Button1") {
      
profile GuiBlueButtonProfile;
      
height 24;
      
text "+";
      
width 24;
      
335;
      
3;
      
hint "Add flag";
    }
    new 
GuiButtonCtrl("addrowsys_Button3") {
      
profile GuiBlueButtonProfile;
      
height 24;
      
text "?";
      
width 24;
      
285;
      
3;
      
hint "help";
    }
    new 
GuiButtonCtrl("addrowsys_Button4") {
      
profile GuiBlueButtonProfile;
      
height 24;
      
text "^";
      
width 24;
      
310;
      
3;
      
hint "Update";
    }
    new 
GuiScrollCtrl("addrowsys_TextList1_Scroll") {
      
profile GuiBlueScrollProfile;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 354;
      
6;
      
32;
      new 
GuiTextListCtrl("addrowsys_TextList1") {
        
profile GuiBlueTextListProfile;
        
height 34;
        
horizsizing "width";
        
sortcolumn 167550464;
        
width 350;
      }
    }
    new 
GuiTextCtrl("addrowsys_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Server Flag Adder.";
      
width 305;
      
9;
      
6;
    }
  }
}

function 
addrowsys_Button4.onAction() {
  
getflags();
}

function 
Extent_Button1.onAction() {
  
addflags();
}

function 
addrowsys_Button3.onAction() {
  
say2("You can add rows#bto the GUI by pressing#bthe + button.#bYou can update the flag#bscreen by pressing the ^ button.");
}

function 
GetFlags() {
  
addrowsys_TextList1.clearrows();
  for (
temp.flagserverr.getdynamicvarnames()) {
    
addrowsys_TextList1.addrow(temp.counttemp.flagtemp.value serverr.(@temp.flag));
    
temp.count++;
  }
}

function 
AddFlags() {
  
triggerserver("gui"this.name"addflags"Extent_TextEdit1.textExtent_TextEdit2.text);
  
getflags();
}

function 
OpenGui() {
  
creategui();
  
addflags();
}

function 
ChatBar.onAction() {   
  if (
ChatBar.text.trim() == "/flagadder") {   
    
OpenGui(); //Opens the GUI. 
    
ChatBar.text ""// Clear the chatbar so /flagadder isn't chatted out loud. 
  
}   

The Graal Pastebin file can be found here.
Have fun!
Attached Thumbnails
Click image for larger version

Name:	emeraserverflagadder.PNG
Views:	306
Size:	17.3 KB
ID:	53560   Click image for larger version

Name:	serverflagadder.PNG
Views:	313
Size:	42.0 KB
ID:	53563  
__________________

Last edited by Emera; 08-27-2011 at 01:31 AM..
Reply With Quote
  #2  
Old 08-26-2011, 05:08 PM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Good job finishing your script. I have a few suggestions, if you feel like improving it.

Before modifying the serverr flag, verify that the player is who it should be. An abusive player could manipulate their client into sending a trigger to this weapon and modify any serverr flag they wish.

PHP Code:
function onActionServerside() {
  if (!(
player.communityname in serveroptions.staff.tokenize(",")))
    return;
  if (
params[0] == "addflags"serverr.(@params[1]) = params[2];

Also, please use
PHP Code:
function ChatBar.onAction() { 
  if (
ChatBar.text.trim() == "/flagadder") { 
    
OpenGui(); //Opens the GUI. 
  


rather than onPlayerChats for chat commands.
Reply With Quote
  #3  
Old 08-26-2011, 05:39 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
Replaced the method for activating the GUI and also added some security. It reads from this.allowed instead of the server options. I don't want every single staff member to have access to this script.

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.allowed = {
    
"Community name 1""Community name 2"
  
};

Then in the main script

PHP Code:
function Extent_Button1.onAction() {
  if (
player.communityname in this.allowed) {
    
addflags();
  }

So you have to be in the this.allowed to be able to use the button to add flags.

And thank you for helping me out

EDIT: Didn't want to double post. It now recognizes your GUI style and adapts its design to fit with it. Say if I was using Toon.wba (best theme ever), the theme would become toon.wba
__________________

Last edited by Emera; 08-26-2011 at 06:52 PM..
Reply With Quote
  #4  
Old 08-26-2011, 07:11 PM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by Emera View Post
Replaced the method for activating the GUI and also added some security. It reads from this.allowed instead of the server options. I don't want every single staff member to have access to this script.
The security check still should be on the server-side. Anything on the client-side should be treated as if it could possibly be manipulated.
Reply With Quote
  #5  
Old 08-26-2011, 11:11 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
Quote:
Originally Posted by 0PiX0 View Post
The security check still should be on the server-side. Anything on the client-side should be treated as if it could possibly be manipulated.
Can I still use
PHP Code:
function onActionServerside() {
  
this.allowed = {"whatever"};

//Rest of code 
Or is there a different way?
__________________
Reply With Quote
  #6  
Old 08-26-2011, 11:15 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
Can I still use
PHP Code:
function onActionServerside() {
  
this.allowed = {"whatever"};

//Rest of code 
Yeah.
__________________
Quote:
Reply With Quote
  #7  
Old 08-26-2011, 11:30 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 Emera View Post
Can I still use
PHP Code:
function onActionServerside() {
  
this.allowed = {"whatever"};

//Rest of code 
Or is there a different way?
If you're going to use a this. variable, you might as well define it in onCreated instead of onActionServerSide.
__________________
Reply With Quote
  #8  
Old 08-26-2011, 11:34 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
Fixed. Added to first post.
PHP Code:
function onActionServerside() {
this.allowed = {
    
"McChucken",
    
"Other community name"
  
};
  if (
params[0] == "addflags")
    if (
player.communityname in this.allowed) {
      
serverr.(@params[1]) = params[2];
    }

__________________
Reply With Quote
  #9  
Old 08-26-2011, 11:44 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Don't do what you did:

PHP Code:
if (statement) if (otherstatement) {


Either do:

PHP Code:
if (statement) {
  if (
otherstatement) {

  }

or even (I prefer using two ifs though):

PHP Code:
if (statement && otherstatement) {


The above two are much more readable and will be easier to modify in the future. When you modify the code.

Also:

PHP Code:
function ChatBar.onAction() {  
  if (
ChatBar.text.trim() == "/flagadder") {  
    
OpenGui(); //Opens the GUI.
    
ChatBar.text ""// Clear the chatbar so /flagadder isn't chatted out loud.
  
}  

__________________
Quote:
Reply With Quote
  #10  
Old 08-26-2011, 11:55 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
Quote:
Originally Posted by fowlplay4 View Post
Don't do what you did:

PHP Code:
if (statement) if (otherstatement) {


Either do:

PHP Code:
if (statement) {
  if (
otherstatement) {

  }

or even (I prefer using two ifs though):

PHP Code:
if (statement && otherstatement) {


The above two are much more readable and will be easier to modify in the future. When you modify the code.

Also:

PHP Code:
function ChatBar.onAction() {  
  if (
ChatBar.text.trim() == "/flagadder") {  
    
OpenGui(); //Opens the GUI.
    
ChatBar.text ""// Clear the chatbar so /flagadder isn't chatted out loud.
  
}  

Oops that was an error. Fixed now.
__________________
Reply With Quote
  #11  
Old 08-27-2011, 12:00 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
Oops that was an error. Fixed now.
No it's not. You're still only using one set of {}'s for two if statements.
__________________
Quote:
Reply With Quote
  #12  
Old 08-27-2011, 12:47 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by Emera View Post
PHP Code:
function onActionServerside() {
  
this.allowed = {
    
"McChucken""Other community name"
  
};
  if (
params[0] == "addflags")  { 
    if (
player.communityname in this.allowed) {
    
serverr.(@params[1]) = params[2];
    }  
  }

It's not necessary to set this.allowed every time the onActionServerSide event is invoked.

PHP Code:
function onCreated() {
  
//set this.allowed to whatever
}

function 
onActionServerSide() {
  
//stuff

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 12:35 PM.


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