Datafiles

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Datafiles

Post by Beaud »

Theses are some functions I am currently coding, I have some issues creating the datafile...

Code: Select all

/*
   Logs.inc v1.0
   Logs Staff, player or script cmd in differents files using
   Andromeda UO's utilsdate available at http://groups.yahoo.com/group/pol-scriptforum/files/.
   Author: Developer Beaud.
   Email: DeveloperBeaud@gmail.com
   TODO:
    Add the scriptname to LogScriptEv returned string.
*/
use os;
use uo;
use datafile;

Include "include/utilsDate";

/*
  LogCMD(text)
  
  Stores strings in a txt file located in X/data/ds/logs/
  
  param text: That string will be logged in its user element an sorted by cmdlevel
              Example: LogCMD("Banned " + who.name + "'s account for cheating");            
         
  Notes: It might be usefull to manage a descent staff team.
*/
function LogCMD(who, text)
	var timedate :=  PolCore().systime;
	timedate := CDateStr(timedate) + " " + CTimeStr(timedate); 
	var path;
	Case(who.cmdlevel)
	0: path := "logs/players";
	1: path := "logs/counselors";
	2: path := "logs/seers"; 
	3: path := "logs/gamemasters";
	4: path := "logs/admins";
	5: path := "logs/developers";
	Endcase
	var ldata := OpenDataFile( path );
	If(!ldata)
		ldata := CreateDataFile( path );
	Endif
	var log := ldata.FindElement(who.acctname);
	if(!log)
		log := ldata.CreateElement(who.acctname);
  else
	endif
	log.setprop(CInt(timedate), text);
	UnloadDataFile(path);
endfunction

/*
  LogScriptEv(text)
  
  Stores strings in a txt file located in X/data/ds/logs/
  
  param text: That string will be looged in its script element.
              Example: LogScriptEv("Banned " + who.name + "'s account for inactivity");
         
  Notes: It might be usefull if you need to locate which script is banning
         which were banned.
*/
function LogScriptEv(text)
	var timedate :=  PolCore().systime;
	timedate := CDateStr(timedate) + " " + CTimeStr(timedate); 
	var path := "logs/ScriptEv";
	var ldata := OpenDataFile( path );
	If(!ldata)
		ldata := CreateDataFile( path );
	Endif
	var log := ldata.FindElement("polcore");
	if(!log)
		log := ldata.CreateElement("polcore");
	endif
	log.setprop(CInt(timedate), text);
	UnloadDataFile(path);
endfunction
Even if there is no */data/ds/logs/*.txt
It read it and doesn't Create the datafile.

Code: Select all

var ldata := OpenDataFile( path );
If(!ldata)
  ldata := CreateDataFile( path );
Endif
But there is no datafile located in */data/ds/logs/, the folder is not even created.

I hope I been enought clear and that someone will help me.
Im using the POL095 core...

Beaud.
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

You have to put the package name into the path.

e.g.:
var path := CStr(":nameofthepackage:test");
Last edited by Pierce on Thu Feb 23, 2006 4:42 am, edited 2 times in total.
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Post by Beaud »

I guess you meant package with such a format ::test.log but Datafiles should be created in */data/ds/...
User avatar
MontuZ
Forum Regular
Posts: 338
Joined: Fri Feb 10, 2006 8:08 am

Post by MontuZ »

after you've logged something save the world and check the data/ds
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Post by Beaud »

I did as well as some shutdown but its like if the file existed since OpenDataFile(path) is true :S

Maybe

Code: Select all

var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif
Is not the good way to do it :?
Mithril
New User
Posts: 25
Joined: Sat Feb 04, 2006 5:15 pm

Post by Mithril »

Yes, datafiles are stored in \data\ds, however, they are referenced internally by package name.

So, you would want your logging script in a package called "logs". Then, you would use OpenDataFile(":logs:logfilename").

You can use whatever package you would like, you don't have to use "logs". But yes, internally, datafiles are refrerenced by :packagename:filename.
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Post by Beaud »

Could you explain the difference btw this entry in datastore.txt..

Code: Select all

DataFile
{
	Descriptor	::sysevent/staff
	Name	sysevent/staff
	Flags	0
	Version	6
	OldVersion	5
}
And mine..

Code: Select all

DataFile
{
	Descriptor	::logs/Developers
	Name	logs/Developers
	Flags	0
	Version	7
	OldVersion	7
}
Why the first one is creating a file called staff.txt in */data/ds/sysevent/..
Mithril
New User
Posts: 25
Joined: Sat Feb 04, 2006 5:15 pm

Post by Mithril »

Just adding an entry to datafile.txt like that doesn't create the datafile. Not that I've ever been able to get it to do anyway, I just tried several different ways to be sure. You need to create the datafile in code.
User avatar
MontuZ
Forum Regular
Posts: 338
Joined: Fri Feb 10, 2006 8:08 am

Post by MontuZ »

Mithril I hope you aren't referring to his last post, because that's not what he asked.

I had this problem too when I first started using datafiles. I forget what I did to fix it. Anyway check out regionspawner package, it has code using datafile.em. Use that as a referrance to fix your problem.
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

Sorry, i surely meant package :wink:
First delete the stuff you have written into the datastore.txt while
the server is down.
Second i think the package is called "logs" where you have this script.
Use this code and the files will be stored in data/ds/..

Code: Select all

/* 
   Logs.inc v1.0 
   Logs Staff, player or script cmd in differents files using 
   Andromeda UO's utilsdate available at http://groups.yahoo.com/group/pol-scriptforum/files/. 
   Author: Developer Beaud. 
   Email: DeveloperBeaud@gmail.com 
   TODO: 
    Add the scriptname to LogScriptEv returned string. 
*/ 
use os; 
use uo; 
use datafile; 

Include "include/utilsDate"; 

/* 
  LogCMD(text) 
  
  Stores strings in a txt file located in X/data/ds/logs/ 
  
  param text: That string will be logged in its user element an sorted by cmdlevel 
              Example: LogCMD("Banned " + who.name + "'s account for cheating");            
          
  Notes: It might be usefull to manage a descent staff team. 
*/ 
function LogCMD(who, text) 
   var timedate :=  PolCore().systime; 
   timedate := CDateStr(timedate) + " " + CTimeStr(timedate); 
   var path; 
   Case(who.cmdlevel) 
   0: path := "players"; 
   1: path := "counselors"; 
   2: path := "seers"; 
   3: path := "gamemasters"; 
   4: path := "admins"; 
   5: path := "developers"; 
   Endcase 
   var ldata := OpenDataFile( path ); 
   If(!ldata) 
      ldata := CreateDataFile( path ); 
   Endif 
   var log := ldata.FindElement(who.acctname); 
   if(!log) 
      log := ldata.CreateElement(who.acctname); 
  else 
   endif 
   log.setprop(CInt(timedate), text); 
   UnloadDataFile(path); 
endfunction 

/* 
  LogScriptEv(text) 
  
  Stores strings in a txt file located in X/data/ds/logs/ 
  
  param text: That string will be looged in its script element. 
              Example: LogScriptEv("Banned " + who.name + "'s account for inactivity"); 
          
  Notes: It might be usefull if you need to locate which script is banning 
         which were banned. 
*/ 
function LogScriptEv(text) 
   var timedate :=  PolCore().systime; 
   timedate := CDateStr(timedate) + " " + CTimeStr(timedate); 
   var path := "ScriptEv"; 
   var ldata := OpenDataFile( path ); 
   If(!ldata) 
      ldata := CreateDataFile( path ); 
   Endif 
   var log := ldata.FindElement("polcore"); 
   if(!log) 
      log := ldata.CreateElement("polcore"); 
   endif 
   log.setprop(CInt(timedate), text); 
   UnloadDataFile(path); 
endfunction 
fileaccess.cfg should be:

Code: Select all

FileAccess
{
  Package *
  Directory *
  AllowRead 1
  AllowWrite 1
  AllowAppend 1
  AllowRemote 1
  Extension .log
}
Last edited by Pierce on Thu Feb 23, 2006 4:41 am, edited 1 time in total.
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Post by Beaud »

Actually this script is an include located in */scripts/include/...
I use the function is some script to log who used which cmd for X reason..
I have no pkg at all, all I want is a log file created somewhere, I was using "logs/*" because I though it would create it in */data/ds/logs/... But all along this topic you guys talked about pkgs an script, Its just a function located in an include file, I don't get it oO.. I just can't make a .log or a .txt out of this function.

That stuff was created in datastore.txt from the function, I never edited any file..

I have no logs pkg it was just a path i wanted the file to be in, I though it */data/ds/ + path..
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Post by Beaud »

SpawnRegion

Code: Select all

function GlobalSpawnGroups()
  var dfile := OpenDataFile("SpawnGroups");
  if(!dfile)
    dfile := CreateDataFile("SpawnGroups");
...
Logs.inc

Code: Select all

var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif 
Beaud
Novice Poster
Posts: 41
Joined: Tue Feb 14, 2006 2:06 pm

Post by Beaud »

That fileaccess interest me though If there is a way to specify the path, the file extention as well it would be better than a simple text file in */data/ds/...
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

Damn i should not post if i am tired :wink:
The above was not quite correct, i edited it. But nevertheless, if this is an include file in scripts/include/ it won't work imho. It has to be in a package to create these datafiles.

If you want to use file.em functions, it will look something that way, e.g.

Code: Select all

use os;
use uo;
use file;

program tc_sayabove( who, text )
    SendSysMessage( who, "Say above what or whom?" );

    var what := Target( who );
    if (what)
        PrintTextAbove( what, text, color := 6 );
    endif
   var filename := "::pkg/opt/LogSystem/"+ who.acct.name + ".log";
   var logtext := who.name + " says above " + what.name;
   if(what.isa(POLCLASS_NPC))
           logtext := logtext + " [" + what.npctemplate + "]: " + text;
   else
           logtext := logtext + " [" + what.acct.name + "]: " + text;
   endif
   LogToFile( filename, logtext );

endprogram
Post Reply