Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Storing with serverr. (https://forums.graalonline.com/forums/showthread.php?t=134264272)

Emera 08-21-2011 03:54 AM

Storing with serverr.
 
I was reading through Fowlplay4's scripting guide and I suddenly decided to make a simple script that stores text on the server, safe from updating a level. I read through the forums and found that the use of serverr to store data was a favored method, so I studied some more on the wiki and decided to go and make a simple GUI interface consisting of a MuliLineTextEditCtrl an a Window. All it does is read from the serverr and displays the text in the multiline. Here is what I have.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
NewsScreen();
  
this.newsteam = {
    
"McChucken""Callimuc"
  
};
  
player.chat "News Updated"//Alerts the player
}

function 
onPlayerChats() {
  if (
player.chat == "!news") {
    
NewsScreen(); //Shows the GUI
  
}
  if (
player.chat.starts("!setnews ")) {
    if (
player.communityname in this.newsteam) { //Protection
      
serverr.news player.chat.substring(9); //Everything after !setnews
    
}
  }
}

function 
NewsScreen() {
  new 
GuiWindowCtrl("News_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,240";
    
isexternal true;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Server News";
    
405;
    
218;
    new 
GuiScrollCtrl("News_MultiLine1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 228;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 308;
      
6;
      
7;
      new 
GuiMLTextCtrl("News_MultiLine1") {
        
profile GuiBlueMLTextProfile;
        
height 16;
        
horizsizing "width";
        
htmlcompatibility true;
        
htmllinks true;
        
text serverr.news;
        
width 283;
      }
    }
  }


The only issue I am having is that when I log out and in again to the server, the text in the multiline is 0 (NULL). What am I missing here. The script has no purpose at all other than helping me learn.

Does the serverr have to be on the serverside to store the data?

0PiX0 08-21-2011 04:39 AM

It's possible that serverr vars haven't been synced to the clientside yet when that script runs.

salesman 08-21-2011 04:45 AM

A serverr.var is read-only on the clientside. You need to set it on the serverside.

I'm not sure it's a good idea to store something like server news (which is only needed on demand) in a variable that is synced with every client. You also have the problem of strings being chopped to 255 characters if a staff member manually edits the flags from RC.

serverr variables are good when a small amount of data is needed frequently on every client. Such as storing the current state of a weather system.

cbk1994 08-21-2011 05:32 AM

As Sales said, you have to set serverr variables on serverside. If they could be set clientside, a "hacker" would be able to change the news for everybody.

The reason it works until you reconnect is that you're temporarily changing the serverr variable on your client only. When you reconnect, the server sends the actual variable. It's like setting a clientr variable on clientside. The value will stick (at least for a while?), but you won't have actually changed the variable on serverside.

Also, RC will trim any server flags down to a certain size (~255 characters?), so if you set server flags with RC, you'll permanently lose anything past that many characters.

You should probably use text files instead of serverr variables for storing server news. There are very few times when server or serverr variables are advisable.

fowlplay4 08-21-2011 06:27 AM

On Zodiac I use text files, and onLevelFileUpdated() to allow people to edit the news.

When the news text file is updated, I store an updated copy in Control NPC. I.e:

PHP Code:

// Player Logs in
// Send them the News
function onPlayerLogin(pl) {
  
temp.news findnpc("Control-NPC").news;
  
pl.triggerclient("-YourNewsSystem""thegoodword"temp.news);
}

// News is updated
function onLevelFileUpdated(filename) {
  if (
filename == "news/news.txt") {
    
findnpc("Control-NPC").news.loadlines("levels/" filename);
    
updateEveryone();
  }
}

// Send Everyone the News
function updateEveryone() {
  
temp.news findnpc("Control-NPC").news;
  for (
temp.aallplayers) {
    
temp.a.triggerclient("-YourNewsSystem""thegoodword"temp.news);
  }



ffcmike 08-21-2011 07:08 AM

I always thought onLevelFileUpdated was only for files downloadable in game by the client, having seen that and confirmed that it does indeed work for any file uploaded this is going to make life a lot easier for certain things I wanted to make.

The more you know :).


All times are GMT +2. The time now is 09:52 AM.

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