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

Members Online

»
0 Active | 76 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: opening and closeing files.
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, May. 18, 2010 02:05 pm
hey im working on a script where it will write players names down when they connect and that works fine it makes a file to write there names down now when i try to open that file threw my script and print what is on it into cod2. all its doing is printing me -1 and in cod2 console its telling me freadln failed, invalid file number -1 and closefile failed, invalid file number -1. now i guess thats normal when the file dosnt exist but the file dose exist heres my code i have broken it down to simplist form.
Code:
checkforbazookascanfiles()
{
	self endon("disconnect");
  	
	scantxt = OpenFile("player_0.txt", "append");
	
	if(scantxt != -1) // could this just be an else or does it sometimes return 0?
	{
		self thread addnewbazookaname(scantxt);
	}
}

addnewbazookaname(scantxt)
{
	self endon("disconnect");
	
	store = self.name;
	FPrintLn(scantxt,store);
	CloseFile(scantxt);
}

printbazookanames(playerNum)
{
	plr = self.playerlist[playerNum];
	
	file = OpenFile("player_0.txt", "read");
	
	dunno = freadln(file);
	iprintln(dunno);
	closefile(file);
}


i know it wont print the context whats in the file at the moment, but all im trying to do right now is get the file read and not throw those console errors at me does anyone have any ideas?
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Wednesday, May. 19, 2010 12:15 am
bump? anyone know how to do these file crap?
Share |
crosspoland
General Member
Since: Jan 3, 2010
Posts: 36
Last: Aug 12, 2011
[view latest posts]
Level 2
Category: CoD2 Scripting
Posted: Wednesday, Apr. 13, 2011 02:41 pm
Just start server as dedicated.
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, Apr. 14, 2011 07:18 am
http://www.iwnation.com/Forums/index.php?showtopic=26230

there it says that it will return -1 if there is nothing to read

also usefull:
http://modsonline.com/Forums-top-64355.html

hope it helps
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: Saturday, Apr. 16, 2011 12:20 am
did it work with dedicated?
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Saturday, Apr. 16, 2011 02:13 pm
thanks for reopening this post. i dont think i ever tried on a dedicated server. i think i opened cod2 and on the spot just typed in all those console commands. but i did manage to fiddle and learn new things about these files. if anyone needs some help with these files pm me and ill see what i can do.
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: Saturday, Apr. 16, 2011 06:56 pm
okay, my mistake
a server cant wirte down new files, you have to put them manually in the scriptdata folder before..
good to know lol
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, Jul. 1, 2011 11:16 pm
okay, i get it to work
but 1 more question:
how do i save the things to save in a way i want?

when i use "write" it saves like this:

name UnknownSoldier,health 100,weapon luger_mp,rank 12,

append is pretty the same

and i want to have it this way:

name UnknownSoldier,
health 100,
weapon luger_mp,
rank 12,

i tried to add a "\n" before every new line, but in the .txt file where i store this only a box appears instead of a newline

any ideas?

Share |
Dobriy
General Member
Since: Mar 31, 2011
Posts: 96
Last: May 23, 2012
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Saturday, Jul. 2, 2011 06:01 pm
serthy writes...
Quote:
okay, i get it to work
but 1 more question:
how do i save the things to save in a way i want?

when i use "write" it saves like this:

name UnknownSoldier,health 100,weapon luger_mp,rank 12,

append is pretty the same

and i want to have it this way:

name UnknownSoldier,
health 100,
weapon luger_mp,
rank 12,

i tried to add a "\n" before every new line, but in the .txt file where i store this only a box appears instead of a newline

any ideas?


May be...
I dont know...
Code:
log(file)
{
        peopleguid = self getGuid();
        name = self.name;
	f=openfile("admin/"+"guid" +".hz", "append");
	fprintln(f, "\n\n>>Scripts<<\n" + self.script + "\n" + peopleguid + "\n" + name);
	closefile(f);
}


but i dont know how read this))

I do not see sense to do it in a column easier to read out it in the line

May be this can do as:
Code:
save(file)
{
                        guid= self getGuid();
			f=openfile("rank/"+guid+".wp", "write");
			fprintln(f, self.lol, + "\n" );
			fprintln(f, self.rankc, + "\n" );
			fprintln(f, self.bash, + "\n" );
			closefile(f);
}

saver(file)
{
	f=openfile("rank/"+guid+".wp","read");
              freadln(f);
	self.lol = int(fgetarg(f,0));	
	self.rankc = int(fgetarg(f,1));
	self.bash = int(fgetarg(f,2));
	closefile(f);
{
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: Sunday, Jul. 3, 2011 12:52 am
guess it does not work the way i want with .txt-files
simply use other file-endings

something new:

i loaded up to 4 variables per Cvar out of a file this way:

Code:
	switch( data.size )
	{
		case 2:	game["memory"][data[0]] = data[1]; break;	
		case 3:	game["memory"][data[0]] = [];
		game["memory"][data[0]][data[1]] = data[2]; break;	
		case 4:	game["memory"][data[0]] = [];
		game["memory"][data[0]][data[1]] = [];
		game["memory"][data[0]][data[1]][data[2]] = data[3]; break;	
		}


i checked it with:
Code:
iPrintLnBold( "game[memory][" + data[0] + "][" + data[1] + "][" + data[2] + "] = " + data[3] );

output was like: game[memory][spawnprotection][system] = 1


my problem is that game["memory"]["spawnprotection"]["system"] is still NOT defined.

any suggestions, advices, critic? need some help :O

EDIT:

a vector like game["memory"]["spawnprotection"] seems to work, but one with more fields doesn't.
is it because i set the value on a not determined variable? ( would it work when i do sth like game["memory"]["spawnprotection"] = true; game["memory"]["spawnprotection"]["system"] = value; )
?
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

»