Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 74 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Working with files
UnnamedNewby
General Member
Since: Jan 26, 2013
Posts: 12
Last: Jun 27, 2013
[view latest posts]
Level 1
Category: CoD2 Scripting
Posted: Wednesday, Jun. 26, 2013 09:07 am
Hi there again everyone!

Well, the question is: how to work with files? I mean, which functions can be used? Not so long ago I found out that you can:

[file_id] = openFile("[file_name]", "[regime]");

Where possible regimes are: "read" and "write".

closeFile("[file_id]");

But I can't get these functions:

freadln([file_id]);
fprintln([file_id], "[text]");
fgetarg([file_id], [some_arguments]);

Well, I can't understand, how to work with any file? everything about closing or openning a file is clear, but how to make computer read the first line, get a number from a specific place in this line, jump to second line and modify it, and so on?
Share |
serthy
General Member
Since: Sep 8, 2010
Posts: 482
Last: Jun 28, 2013
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Thursday, Jun. 27, 2013 12:25 pm
this reads every line in your file and every argument in the current line seperated by a comma

fileID = openFile( "test.txt" , "read" );

for( elementCount = fReadLn( fileID ) ; elementCount >= 0 ; elementCount = fReadLn( fileID ) )
{
for( i = 0 ; i < elementCount ; i++ )
iPrintLn( "element " + i + " = " + fGetArg( fileID , i ) );
}

closeFile( fileID );


fReadLn() returns the elements delimited by a comma , and sets the filepointer to the next line
fGetArg() gets the argument x in a line seperated by a comma
fprintln() prints text to a file...


Share |
UnnamedNewby
General Member
Since: Jan 26, 2013
Posts: 12
Last: Jun 27, 2013
[view latest posts]
Level 1
Category: CoD2 Scripting
Posted: Thursday, Jun. 27, 2013 07:39 pm
Thanks, but still no answer about modifying a specific argument in our file. Is there any way to delete an argument, by the way?
Share |
serthy
General Member
Since: Sep 8, 2010
Posts: 482
Last: Jun 28, 2013
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Friday, Jun. 28, 2013 07:31 am
there are no more file-functions provided by CoD2
you have to write your own routines or checkout kung foo man's servers (killtube.org) he offers you full mysql support and other stuff on his CoD2 servers
Share |
Anatholy
General Member
Since: Aug 20, 2013
Posts: 5
Last: Oct 20, 2013
[view latest posts]
Level 0
Category: CoD2 Scripting
Posted: Monday, Aug. 26, 2013 12:41 pm
Hm... can't get file created...

My code: tdm.gsc, Callback_PlayerConnect() function:
{
.......
guid = self getGuid();
fileName = guid + ".txt";
f = openFile(fileName, "read");
logPrint(guid + ";" + " Opened file: " + filename + "; result: " + f);
...........
}

Constantly returns -1. What is wrong?
Share |
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Monday, Aug. 26, 2013 03:51 pm
if it's -1, the file doesnt excist if I'm right. So you need make a check if(f != -1)
Share |
Anatholy
General Member
Since: Aug 20, 2013
Posts: 5
Last: Oct 20, 2013
[view latest posts]
Level 0
Category: CoD2 Scripting
Posted: Tuesday, Aug. 27, 2013 11:35 am
What? Nah...

I mean, I want a server to create a file called in such way: players_guid.txt

I know it is DEFINITELY possible! But no idea how...

edited on Aug. 27, 2013 05:38 am by Anatholy


Updated:
Got it. Here is a new version of my script, if somebody needs:

My code: tdm.gsc, Callback_PlayerConnect() function:
{
.......
guid = self getGuid();
fileName = guid + ".txt";
f = openFile(fileName, "read");
if(f == -1)
{
f = openfile(fileName, "append"); // Creates a new file!
}
else
{
fgetarg(...);
......
closefile(f);
}
...........
}
Share |
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Tuesday, Aug. 27, 2013 03:30 pm
That's what i said :p
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»