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-11-2011, 12:59 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Wink News System

I've noticed that most UC servers are looking for news systems.
Add this to all players and poof you can easily edit the news from the client, within the news system. Also, you can use HTML code so that you can edit your news more cleanly. This is what my news code on Vortex looks like so far.
PHP Code:
<font color yellow> <font size 5> <center> <bWelcome To Vortex! </b> </center> <font size 3><font color black> <br><b8/10 - </b>8/10 Test News 3 <br><b8/10 - </b>Test News 2<br><b8/10 - </b>Test Image: <img src "block.png"> (test news 1
That was just a few tests

Some HTML coding is
PHP Code:
<font color COLOR> (Changes Color)
<
font size =  #> (Changes Size)
<bHi </b> (Makes Hi bold)
<
br> (Skips a line)
<
img src "block.png"> (Would show block.png)
<
img src "http://www.mariowiki.com/images/thumb/f/ff/MvsDK_Toad.jpg/180px-MvsDK_Toad.jpg"> (Would show the link's image)
<center> Middle </center> (Centers the word Middle) 
So, load this up in a weapon, also to edit who can edit the news get to line 122 and add your account to this.can. For all of you new scripters to add something to an array edit the array like this

PHP Code:
this.can = {"FIRST ACCOUNT""SECOND ACCOUNT""THIRD ACCOUNT"}; 
Okay, so here's the script, just load it in to a weapon, and add it to all player. Oh, and you can also toggle its visibility by pressing N.

PHP Code:
function onActionServerSide() {
  if (
params[0] == "getNews") {
    
triggerclient("gui"this.name"returnNews"serverr.news);
  }
  if (
params[0] == "Publish") {
    
serverr.news params[1];
    for (
temp.pallplayers) {
      
p.triggerclient("gui"this.name"NNews");
    }
  }
  if (
params[0] == "reGetNews") {
    
triggerclient("gui"this.name"Editor"serverr.news);
  }
}

//#CLIENTSIDE
function onCreated() {
  
getIt();
}

function 
onKeyPressed(codekeyscancode) {
  if (
key == "N") {
    if (
NNews_Window1.visible == false) {
      
getIt();
    } else {
      
NNews_Window1.hide();
    }
  }
}

function 
getIt() {
  
triggerserver("gui"this.name"getNews");
}

function 
onActionClientSide() {
  if (
params[0] == "returnNews") {
    
openNews(params[1]);
  }
  if (
params[0] == "NNews") {
    
getIt();
  }
  if (
params[0] == "Editor") {
    
openNEditor(params[1]);
  }
}

function 
openNews(newz) {
  
NNews_Window1.show();
  new 
GuiWindowCtrl("NNews_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "737,343";
    
canmove false;
    
canclose false;
    
canmaximize false;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
text "News";
    
ScreenWidth 350;
    
ScreenHeight 150;
    new 
GuiButtonCtrl("NNews_Button1") {
      
profile GuiBlueButtonProfile;
      
height 34;
      
text "Close News [N]";
      
width 737;
      
309;
    }
    new 
GuiButtonCtrl("NNews_Button2") {
      
profile GuiBlueButtonProfile;
      
height 34;
      
text "Edit News (Admin Only)";
      
width 737;
      
275;
    }
    new 
GuiScrollCtrl("NNews_MultiLine1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 231;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 737;
      
34;
      new 
GuiMLTextCtrl("NNews_MultiLine1") {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
plaintext "Multi Line Text Field Standard Content";
        
text newz;
        
width 712;
      }
    }
    new 
GuiTextCtrl("NNews_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Created By Toad";
      
width 111;
      
626;
    }
  }
}

function 
NNews_Button1.onAction() {
  
NNews_Window1.hide();
}

function 
NNews_Button2.onAction() {
  
this.can = {
    
"Graal749201""Graal754954"
  
};
  if (
player.account in this.can) {
    
NNews_Window1.hide();
    
triggerserver("gui"this.name"reGetNews");
    
NNews_Window2.show();
  } else {
    
player.chat "I don't have rights!";
  }
}

function 
openNEditor(newk) {
  new 
GuiWindowCtrl("NNews_Window2") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "860,376";
    
canmove true;
    
canresize false;
    
canmaximize false;
    
canclose false;
    
canminimize false;
    
closequery false;
    
destroyonhide false;
    
text "News Editor";
    
ScreenWidth 400;
    
ScreenHeight 150;
    new 
GuiTextCtrl("NNews_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "HTML coding is included!";
      
width 162;
      
345;
      
7;
    }
    new 
GuiScrollCtrl("NNews_MultiLineEdit1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 294;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 860;
      
31;
      new 
GuiMLTextEditCtrl("NNews_MultiLineEdit1") {
        
profile GuiBlueMLTextEditProfile;
        
height 17;
        
horizsizing "width";
        
plaintext newk;
        
text newk;
        
width 835;
      }
    }
    new 
GuiButtonCtrl("NNews_Button3") {
      
profile GuiBlueButtonProfile;
      
height 37;
      
text "Publish News (done)";
      
width 860;
      
339;
    }
  }
}

function 
NNews_Button3.onAction() {
  
NNews_Window2.hide();
  
triggerserver("gui"this.name"Publish"NNews_MultiLineEdit1.getText());

I am also working on updates such as Tabs for like event news, or any other news needed.
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!



Last edited by Astram; 08-11-2011 at 01:16 AM.. Reason: Beautified
Reply With Quote
  #2  
Old 08-11-2011, 01:01 AM
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
Screenshots?

PHP Code:
this.can = {"FIRST ACCOUNT""SECOND ACCOUNT""THIRD ACCOUNT}; 
You missed out a " so that would screw the whole code.
PHP Code:
this.can = {"FIRST ACCOUNT""SECOND ACCOUNT""THIRD ACCOUNT"}; 
and also
PHP Code:
function GetIt() { 
Couldn't you use functions that give a hint into what it is doing? I.e maybe GetText() or GetNews()
__________________

Last edited by Emera; 08-11-2011 at 01:15 AM.. Reason: Too long.
Reply With Quote
  #3  
Old 08-11-2011, 01:10 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Quote:
Originally Posted by Emera View Post
Screenshots?

PHP Code:
this.can = {"FIRST ACCOUNT""SECOND ACCOUNT""THIRD ACCOUNT}; 
You missed out a " so that would screw the whole code.
PHP Code:
this.can = {"FIRST ACCOUNT""SECOND ACCOUNT""THIRD ACCOUNT"}; 
Thanks (fixed)
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #4  
Old 08-11-2011, 01:12 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
Style your code properly, if you don't know how use my 'GS2 beautifier'.

Instructions:
1. Go to http://fp4.ca/gs2beautifier/
2. Paste your code into the window
3. Click 'Beautify GS2'

Replace your code on the forums with the 'beautified' version.

@Emera: Did you really have to quote the OP? It's just wasting space.
__________________
Quote:
Reply With Quote
  #5  
Old 08-11-2011, 01:13 AM
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
Style your code properly, if you don't know how use my 'GS2 beautifier'.

Instructions:
1. Go to http://fp4.ca/gs2beautifier/
2. Paste your code into the window
3. Click 'Beautify GS2'

Replace your code on the forums with the 'beautified' version.

@Emera: Did you really have to quote the OP? It's just wasting space.
You beat me to it! And OP?
__________________
Reply With Quote
  #6  
Old 08-11-2011, 01:14 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
You beat me to it! And OP?
His whole first post, it's also immortalizing any previous mistakes and makes the thread twice as long to scroll through.
__________________
Quote:
Reply With Quote
  #7  
Old 08-11-2011, 03:27 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Thanks for helping FP4
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #8  
Old 08-11-2011, 09:04 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
On topic:

Big Issues

serverr variables are automatically synced with the client so there's no reason for your script to request, and pull the data from the server because it already has it.

You would be better off storing the news data in a DB-NPC instead of a server variable, if someone updates the server flags with RC it will probably break your news variable if it's too long.

Your 'this.can' array for those who can change the news is pointless because you don't verify it on the server-side so a hacker can easily update it without issue.

Minor Issues

As Emera pointed out getIt() is a very non-descriptive, renaming it getNews() or getNewsData() would be much more helpful.

You don't log (savelog2) when news changes occur, log information like this is useful when abuse happens.

Your calculation to center the news is a little off. To center it properly:

PHP Code:
= (screenwidth width) / 2;
= (screenheight height) / 2
Your 'this.can' variable should probably be defined in your onCreated method instead to make it easier for others to configure the script.

On the server-side I would recommend adding:

PHP Code:
function setNews(new_news) {
  
serverr.news new_news;
}

function 
getNews() {
  return 
serverr.news;

and calling those functions instead of setting them directly in onActionServerSide. It makes it looks cleaner and is easier to extend and maintain in the long run.
__________________
Quote:
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 04:39 AM.


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