Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Hooking and file accessing (https://forums.graalonline.com/forums/showthread.php?t=68679)

projectigi 09-12-2006 11:10 AM

Hooking and file accessing
 
Hi,
  1. are there any functions to directly access files?(that means not, savevars or whatever)
  2. why doesnt savevars saves into levels/ and all subfolders of levels/ but the graal.wiki.net example of savevars uses levels/ ?
  3. how to hook things?
    i talked to someone and said something like "it would be nice if you could execute a script everytime a weapon is saved / so like i could make a mysql class and every weapon that gets saved gets added a join('mysql_class') at the serverside and clientside end"
    he said: "that possible"
    i asked "how?"
    he said: "with hooks, my system uses them"
    but he was working so how do i make these hooks?

KuJi 09-12-2006 01:19 PM

Savestring + Loadstring might be what you want:

http://wiki.graal.net/index.php/Crea...Output_Methods

projectigi 09-12-2006 01:31 PM

No, i search direct file access functions, so i can save things into levels/ and the subfolders of levels/
that doesnt seem to work with savestring or savevars

edit:
OT: btw is graal.net down?
doesnt load for me lol

ApothiX 09-12-2006 02:27 PM

I'm pretty sure there is no traditional hooking in gscript. but the onCreated() event is called when a weapon is saved serverside.

projectigi 09-12-2006 03:02 PM

for every weapon? i guess only the weapon that got saved or? xD

Yen 09-12-2006 09:15 PM

Yay for wasting my post.

I don't know what you mean by 'directly accessing a file.'
It's possible to load the file as raw text, the way it would appear in wordpad, by using loadlines() and savelines().

All of the 'save<whatever>' functions require a full path. The syntax is save<whatever>(path,append?)
If you want to save text to a file 'zomg.txt' in levels/, you need to do object.savelines("levels/zomg.txt",false);

In the case of savelines, it expects the object to be an array. Each array member is one line.
PHP Code:

temp.lines = {"Hi","how","are","you"};
temp.lines.savelines("levels/test.txt",false);
// Output will look like:
// Hi
// how
// are
// you 

In the case of savevars, it expects an object (normally a TStaticVar)
PHP Code:

temp.myobject = new TStaticVar();
with (temp.myobject) {
  
this.zomg "Hello";
  
this.cat "dog";
  
this.moo 123;
}
temp.myobject.savevars("levels/test.txt",0);
//Output will look like:
//zomg=Hello
//cat=dog
//moo=123 

You don't need to define the TStaticVar in most cases, you could just do temp.myobject.zomg = "Hello"; and so on.

Finally, savestring is pretty much the same thing as savelines but it saves the text in a single line. The object it expects is just a string, float, integer, ect.
PHP Code:

temp.mystring "Hello, how are you today?";
temp.mystring.savestring("levels/test.txt",0);
// Output will look like:
// Hello, how are you today? 


KuJi 09-12-2006 10:01 PM

Quote:

Originally Posted by Yen
Yay for wasting my post.

I don't know what you mean by 'directly accessing a file.'
It's possible to load the file as raw text, the way it would appear in wordpad, by using loadlines() and savelines().

All of the 'save<whatever>' functions require a full path. The syntax is save<whatever>(path,append?)
If you want to save text to a file 'zomg.txt' in levels/, you need to do object.savelines("levels/zomg.txt",false);

In the case of savelines, it expects the object to be an array. Each array member is one line.
PHP Code:

temp.lines = {"Hi","how","are","you"};
temp.lines.savelines("levels/test.txt",false);
// Output will look like:
// Hi
// how
// are
// you 


Ahh, thats what I ment** My bad =(

projectigi 09-13-2006 01:51 PM

well i found out that it actually saved, but didn't show up on the File Browse until doing /refreshfilelist ¬_¬


All times are GMT +2. The time now is 08:49 PM.

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