Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-06-2012, 12:31 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Feedback Scipt - Help

So I'm having a bit of a problem understanding how to store information into a weapon script.
I have made a simple Feedback script, But the problem is that I'm having troubles learning how to keep the added rows.
For example:

When i'm Online:
(Someone uses feedback) >
(I manage feedback) >
(It shows up).

When i'm Offline:
(Someone uses feedback) >
(I get on to manage feedback) >
(It does not show up).

Same with if I relog (of course).

So I need help LEARNING how to store information like this, as I have never done it before.

PHP Code:
function onActionServerSide() {
  if (
params[0] == "fsend") {
    for(
temp.pl allplayers) {
      
temp.pl.triggerclient("gui",this.name,"fendt"params[1]);
    }
  }
}

//#CLIENTSIDE
function onActionClientSide() {
  if (
params[0] == "fendt") {
    
Feedback_List.addrow(0params[1]);
  }
}

function 
onCreated() {
  
join("Feedback_Memory");
  
this.fon false;
  
this.mprs false;
  
this.Admins = {"Graal781471""dylan"};
}

function 
onKeyPressed(Code,Key) {
  if (
Key == "o" || Key == "O") {
    if (
this.fon == false) {
      
this.fon true;
      
onFeedBackShow();
      
player.chat "Feedback Test On!";
    } else if (
this.fon == true) {
      
this.fon false;
      
onFeedBackClose();
      
player.chat "Feedback Test Off!";
    }
  }
}

function 
onFeedBackShow() {
  
this.mprs false;
  
onFeedBack();
  
Feedback_Window1.show();
  
Feedback_Checkbox1.show();
  
Feedback_Text1.show();
  
Feedback_Button1.show();
  
Feedback_Button2.show();
  
Feedback_TextList1.show();
  
Feedback_List.hide();
}

function 
onFeedBackClose() {
  
this.mprs false;
  
onFeedBack();
  
Feedback_Window1.hide();
  
Feedback_Checkbox1.hide();
  
Feedback_Text1.hide();
  
Feedback_Button1.hide();
  
Feedback_Button2.hide();
  
Feedback_TestList1.hide();
  
Feedback_List.hide();
}

function 
onFeedBack() {
  new 
GuiWindowCtrl("Feedback_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "172,53";

    
canclose false;
    
width 400;
    
height 100;
    
canmaximize false;
    
canminimize false;
    
canmove false;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text "             Feedback";
    
610;
    
261;
  new 
GuiCheckBoxCtrl("Feedback_CheckBox1") {
    
profile GuiBlueCheckBoxProfile;
    
height 30;
    
width 100;
    
text "Feedback Sent";
    
5;
    
5;
    
checked false;
  }
  new 
GuiTextEditCtrl("Feedback_Text1") {
    
profile "GuiBlueTextEditProfile";
    
horizSizing "width";
    
vertSizing "top";
    
position "100 370";
    
5;
    
35;
    
width 10;
    
extent "360 25";
    
historySize 100;
    
tabComplete true;
  }
  new 
GuiButtonCtrl("Feedback_Button1") {
    
profile GuiBlueButtonProfile;
    
height 24;
    
text "Send";
    
width 100;
    
265;
    
5;
  }
  new 
GuiButtonCtrl("Feedback_Button2") {
    
profile GuiBlueButtonProfile;
    
height 24;
    
text "Manage Feedback";
    
width 125;
    
115;
    
5;
  }
    new 
GuiTextListCtrl("Feedback_List") {
      
profile GuiBlueTextListProfile;
      
height 53;
      
horizsizing width;
      
width 1500;
      
sortmode "name";
      
sortorder "ascending";
      
50;
      
35;
      
sort();
    }
  }
}

function 
Feedback_Button1.onAction() {
  if (
Feedback_CheckBox1.checked == true) {
    
triggerserver("gui",this.name,"fsend"Feedback_Text1.text);
    
onFeedBack();
    
Feedback_List.hide();
    
Feedback_Text1.text "";
    
Feedback_CheckBox1.checked false;
  } else {
    
onFeedBackClose();
    
this.fon false;
    
player.chat "I need to press the checkmark first!";
  }
}

function 
Feedback_Button2.onAction() {
  if (
player.account in this.Admins) {
    
this.mprs true;
    
player.chat "Managing Feedback...";
    
onFeedBack();
    
Feedback_Window1.height 150;
    
Feedback_List.show();
  } else {
    
player.chat "I don't have read rights!";
  }
}

function 
onPlayerChats() {
  if (
player.chat.starts("/clearfeedback")) {
    if (
player.account in this.Admins) {
      
player.chat "I have cleared "addrows(0) @" feedback!";
      
onFeedBack();
      
Feedback_List.clearrows();
    } else {
      
player.chat "I am not authorized!";
    }
  }

THANKS!
-Fysez

EDIT: Sorry just noticed it says "scipt"

Last edited by Fysez; 08-06-2012 at 12:57 AM.. Reason: Lol@Title
Reply With Quote
  #2  
Old 08-06-2012, 03:18 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
I made this post a while back for someone with a similar question on creating a mail system. It is applicable to your situation as well.

Quote:
Originally Posted by cbk1994 View Post
You will want to choose a way to store the data. The four main ones are:
  • Database NPC flags
  • Files
  • SQLite
  • Player flags

The first one should be thrown out in this case as all information you store will be kept in memory. When Era used flags like this, we were using almost 250 MB of memory just for the database, which caused a lot of problems for the rest of the server.

I would also throw out the last one since the data would still be kept in memory as long as the player was online, and RC will truncate any player flags to ~255 characters in length. In addition, if the player were to be reset, they would lose all of their mail.

Both files and SQLite are acceptable in this case. I would recommend SQLite for this instance, but it has a far larger learning curve, and if you use it without understanding it you can cause major problems. If you're interested in taking the SQL route, there are some tutorials available on the internet. I started on a guide here—it's lacking a lot of stuff right now, though.

Graal data files are very simple. They are simply a set of variables and values, one per line, that looks like this:
PHP Code:
foo=bar
baz
="a","b"
test=92 
If we pretend that this file is located at data/test.txt, then we can use the following code to access it:

PHP Code:
temp.vars.loadVars("data/test.txt");

echo(
temp.vars.foo); // echoes "bar"
echo(temp.vars.baz[0]); // echoes "a"
echo(temp.vars.test 9); // echoes "101" 
Saving variables is equally simple:

PHP Code:
// defining the variable like this may or may not be necessary;
// I do it to clarify my purpose
temp.vars null;

temp.vars.stringExample "one";
temp.vars.arrayExample = {"a""b"76};
temp.vars.numberExample 47;

// first parameter is location to save to
// second parameter is whether or not to append
//    false = erase the existing file, replace it with this
//    true  = add these values to the existing file
temp.vars.saveVars("data/test.txt"false); 
Note that in order to allow scripts to access files, you need to give the NPC-server rights to those files, just like if it were a staff member. Open the rights of (npcserver) and add to their folder rights:

Quote:
rw data/*
rw data/*/*
rw data/*/*/*
rw data/*/*/*/*
(I like to keep all the script data inside a data directory and organized into subdirectories—you can choose your own structure, though)

Be careful not to give the NPC-server rights to scripts or levels unless you trust everyone on RC. Anyone with script or level rights could then download them.

Either way you choose for storing data, be sure to think about how you plan to structure it first. If you use files, my recommendation would be to use a file for each player rather than one file for every player. Otherwise, it will still be loading all of that data into memory every time you check the player's mail.

If you have any questions I'm happy to answer them.
In reality though, it may be better to just save the feedback to a log and review it at your leisure. It's easy to get caught up making stuff like this that doesn't directly benefit your server and ignore the actual server content.
__________________
Reply With Quote
  #3  
Old 08-06-2012, 04:26 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Quote:
Originally Posted by cbk1994 View Post
I made this post a while back for someone with a similar question on creating a mail system. It is applicable to your situation as well.



In reality though, it may be better to just save the feedback to a log and review it at your leisure. It's easy to get caught up making stuff like this that doesn't directly benefit your server and ignore the actual server content.
So I have not tested this yet, but just to see if I'm catching on,
I should do something like:

PHP Code:
temp.vars NULL;
temp.vars.memory params[1];
addrow(0temp.vars.memory);
temp.vars.saveVars("data/FeedBack"false); 
?
Or am I way off on this?

PN: I would test this but I'm not currently home.
Is this right, Or am I way off on path?
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 07:06 PM.


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