Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Editing .txt files (https://forums.graalonline.com/forums/showthread.php?t=134264036)

Astram 07-30-2011 05:40 PM

Editing .txt files
 
How can you edit .txt files online, with multiline edit, and then save it? Like
lets say this is in pwn.txt "HI there". Then, how would you edit pwn.txt from "HI there" to "NOOB" and save it?

cbk1994 07-30-2011 06:19 PM

PHP Code:

temp.lines = {
  
"first line",
  
"second line",
  
"third line"
};

// if you want to append to the file instead of replacing, second parameter
// should be true
temp.lines.saveLines("path/to/file.txt"false); 

Serverside, obviously, and (npcserver) needs rw (folder rights) to the specified file.

To get an array of lines from a text file,

PHP Code:

temp.lines.loadLines("path/to/file.txt"); 


fowlplay4 07-30-2011 06:41 PM

Quote:

Originally Posted by fowlplay4 (Post 1634392)
Here's some basic examples for the savestring and savelines functions.

PHP Code:

// Declare Filename
temp.filename "path/to/file.txt";
// Save Lines
temp.lines = {
  
"Line 0: Hello",
  
"Line 1: World!"
  "Line 2: How are you?"
};
temp.lines.savelines(temp.filename0);
// Save String
temp.str "Hello World!\n";
temp.str.savestring(temp.filename0);
// Append String to File
temp.str "Yeah!\n";
temp.str.savestring(temp.filename1);
// Append Lines to File
temp.lines.savelines(temp.filename1); 


Quote:

Originally Posted by fowlplay4 (Post 1634425)
This works just fine, the file will look messed up (all on one line) in regular Windows Notepad (Terriblepad) instead use Wordpad or Notepad++

PHP Code:

function onActionServerSide() {
  
temp.filename "cartridge/test.txt";
  if (
params[0] == "load") {
    
temp.lines.loadlines(temp.filename);
    
player.triggerclient(this.name"load"temp.lines);
  }
  else if (
params[0] == "save") {
    
params[1].savelines(temp.filename0);
  }
}

//#CLIENTSIDE

function onActionClientSide() {
  if (
params[0] == "load") {
    
TestWindowML.setlines(params[1]);
  }
}

function 
onCreated() {
  new 
GuiWindowCtrl("TestWindow") {
    
100;
    
100;
    
width 300;
    
height 300;
    new 
GuiScrollCtrl("TestWindowScroll") {
      
4;
      
20;
      
width 296;
      
height 280;
      new 
GuiMLTextEditCtrl("TestWindowML") {
        
2;
        
width 280;
        
height 280;
      }
    }
  }
  
triggerserver("gui"name"load");
}

function 
ChatBar.onAction() {
  if (
ChatBar.text == "/save") {
    
temp.lines TestWindowML.getlines();
    
triggerserver("gui"this.name"save"temp.lines);
    
ChatBar.text "";
  }



Also linked on my tutorial.

Astram 07-30-2011 09:33 PM

Also, I have
PHP Code:

function onActionServerSide()
  {
  if (
params[0] == "debug")
    {
    
temp.filename "weapons/weaponDrag.txt"
    
temp.lines.loadlines(temp.filename); 
    
player.chat temp.lines;
    
player.triggerclient(this.name"load"temp.lines);
    }
  } 

and I have the weapon "Drag" on the server, but my player.chat always is "0"... Any help?

cbk1994 07-30-2011 10:00 PM

Quote:

Originally Posted by Astram (Post 1660920)
and I have the weapon "Drag" on the server, but my player.chat always is "0"... Any help?

Does (npcserver) have read rights to it?

Deas_Voice 08-13-2011 10:20 PM

Quote:

Originally Posted by Astram (Post 1660920)
Also, I have
PHP Code:

function onActionServerSide()
  {
  if (
params[0] == "debug")
    {
    
temp.filename "weapons/weaponDrag.txt"
    
temp.lines.loadlines(temp.filename); 
    
player.chat temp.lines;
    
player.triggerclient(this.name"load"temp.lines);
    }
  } 

and I have the weapon "Drag" on the server, but my player.chat always is "0"... Any help?

Quote:

Originally Posted by cbk1994 (Post 1660922)
Does (npcserver) have read rights to it?

this, and you forgot the "gui" parameter before this.name on the triggerclient.

i would also believe that setting the player.chat wouldnt work due the textlimit on 256 chars, so try something like echo or sendrpgmessage instead

Mark Sir Link 08-13-2011 11:51 PM

Quote:

Originally Posted by Deas_Voice (Post 1663418)
this, and you forgot the "gui" parameter before this.name on the triggerclient.

i would also believe that setting the player.chat wouldnt work due the textlimit on 256 chars, so try something like echo or sendrpgmessage instead


The GUI parameter is not required for triggerclient.

TServerPlayer.triggerclient(str) vs triggerserver(str, str)


Quote:

Originally Posted by cbk1994 (Post 1660922)
Does (npcserver) have read rights to it?


for some incredibly stupid reason this is not a requirement for loading files, the NPC Server can load any file at any time, only requires write for savelines

cbk1994 08-14-2011 12:16 AM

Quote:

Originally Posted by Mark Sir Link (Post 1663428)
for some incredibly stupid reason this is not a requirement for loading files, the NPC Server can load any file at any time, only requires write for savelines

Are you sure? Just tested it and read rights are required for me.

Mark Sir Link 08-14-2011 05:51 AM

Just tested this on Unholy Nation, server had no rights to weapons folder.

PHP Code:

function onCreated(){
  
temp.= new TGraalVar();
  
f.loadlines("weapons/weaponJoltbomb.txt");
  echo(
f);


Echo output:
GRAWP001,"REALNAME Joltbomb","IMAGE joltbomb.png",SCRIPT,"function onactionserverside() {"," if (params[0] == ""reduce"") {"," player.bombs -= 1;"," }",},//#CLIENTSIDE,"function onweaponfired() {"," if (player.bombs < 1) return(0);"," if (player.level.name == ""unevent_platforms.nw"") {"," player.chat = ""A magical force is blocking you."";"," return(0);"," }"," freezeplayer(0.2);"," setani(""grab"","""");"," triggerserver(""gui"",this.name,""reduce"");"," putbomb(3,player.x%64+vecx(player.dir)*2+0.5,playe r.y%64+vecy(player.dir)*2+0.5);",},SCRIPTEND

cbk1994 08-14-2011 05:56 AM

Quote:

Originally Posted by Mark Sir Link (Post 1663466)
Just tested this on Unholy Nation, server had no rights to weapons folder.

Just tested again and read rights are definitely required on Ol' West. Stefan may have some option turned on for UN to not require it?

I know I've had issues where read rights were required in the past on servers.

Also, why are you using 'new TGraalVar'?

Quote:

Originally Posted by RC
Script: Couldn't create object: type TGraalVar is not existing at line 2 in script of TempChris


Mark Sir Link 08-14-2011 06:23 AM

just a habit I have from other languages, it seems bizarre to me to just immediately use an object without defining it.

I also don't get any RC error like that.

cbk1994 08-14-2011 07:07 AM

Quote:

Originally Posted by Mark Sir Link (Post 1663471)
just a habit I have from other languages, it seems bizarre to me to just immediately use an object without defining it.

I also don't get any RC error like that.

Does UN have error reporting (at runtime) logging to RC? Check that the "logscripterrorstofile" server option is false.

Arrays aren't objects any more than a normal string or number, defining it like that is just silly, not to mention wrong.

Quote:

Originally Posted by scripthelp
TGraalVar - object type, cannot be created by script

Would you do

PHP Code:

temp.gravity = new TGraalVar();
temp.gravity 3

?

Mark Sir Link 08-14-2011 07:28 AM

I guess the thing that seems the most awkward to me about it is both creating and filling the object by a function rather than an equal sign. Something about

temp.f.loadlines("textfile") creating object f and inserting data just seems wrong to me

I guess I should probably stop since it can't be created by script, but I'd probably to start commenting every time I use it because I'd wonder where it came from later in the script


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

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