1
Modification Help / A Guide to Document Altering
« on: October 27, 2007, 08:46:23 PM »
This guide will show you how to set up functions that will read and write on Documents. It is very helpful for keeping a permanent memorabilia of events. These can be automatic or manual. I will show you both.
Lets get started. I will show you the basic principals of reading and writing.
To keep things organized, create a folder called "manipulate"
Make a new document inside that folder and call it: script_stickynote.cs
Open it up and type this in:
Save and, in the same folder, make a document. Call it whatever you want, but make sure it's extention is .txt. Put inside the document we just made this:
Save and open up blockland. Make sure script_stickynote.cs is checked.
Type this in: /docread *NAME OF THE DOC YOU JUST MADE and press enter. You should get this:
That's the basics of a document read. Now it's time to write.
Add this to your stickynote.cs:
Now save, execute the file, and type: /docwrite *NAME OF THE DOCUMENT* HelloSPCMySPCGoodSPCFriend!
You'll get this:
Type
/docread *NAME OF THE DOCUMENT*
And you should get this:
More to come.
Lets get started. I will show you the basic principals of reading and writing.
To keep things organized, create a folder called "manipulate"
Make a new document inside that folder and call it: script_stickynote.cs
Open it up and type this in:
Code: [Select]
function ServerCmdDocRead(%client, %doc)
{
%file = new FileObject(); // This makes %file a File-Type Variable
if(!isFile("Add-Ons/manipulate/" @ %doc @ ".txt")) { messageClient(%client,"","This file does not exist."); return;} // Without this Test-For-Existence code, an invalid file name would spell crash.
%file.openforRead("Add-Ons/manipulate/" @ %doc @ ".txt"); // Sets the value of %file
while(!%file.isEOF()) // Will loop through every line of the file until 'End of File'
{
%line = %file.readLine(); //%line = the current line
messageClient(%client,"","\c2" @ %line); //Tells the client the line
}
messageClient(%client,"","\c6End of File"); //Tells the client the document has been ended
%file.close(); //Closes the document
%file.delete(); //Deletes the *VARIABLE*
}
Save and, in the same folder, make a document. Call it whatever you want, but make sure it's extention is .txt. Put inside the document we just made this:
Quote
Good Job!
Much success!
Save and open up blockland. Make sure script_stickynote.cs is checked.
Type this in: /docread *NAME OF THE DOC YOU JUST MADE and press enter. You should get this:
Quote
Good Job!
Much success!
End Of Document
That's the basics of a document read. Now it's time to write.
Add this to your stickynote.cs:
Code: [Select]
function ServerCmdDocWrite(%client, %doc, %write)
{
%write = strreplace(%write, "SPC", " "); // Replaces the word 'SPC' with a space. Cheap ass way of avoiding the 50 variable method.
%file = new FileObject();
if(!isFile("Add-Ons/manipulate/" @ %doc @ ".txt")) { messageClient(%client,"","This file does not exist."); return;}
%file.openforWrite("Add-Ons/manipulate/" @ %doc @ ".txt"); // Opens the Document for Writing
%file.writeline(%write); // Writes the Line
messageClient(%client, "", "\c2The file was written upon."); //Alerts client that the file has been written to
%file.close();
%file.delete();
}
Now save, execute the file, and type: /docwrite *NAME OF THE DOCUMENT* HelloSPCMySPCGoodSPCFriend!
You'll get this:
Quote
The File was written Upon
Type
/docread *NAME OF THE DOCUMENT*
And you should get this:
Quote
Hello My Good Friend
End Of Document
More to come.