Loop dini files?
#1

I'm making my gamemode with dini, and no problem there.

However, I'm thinking of adding houses and some sort of business system.

I don't know how this would be done with dini, but I'm thinking something like:

• Type command in-game
• sscanf that command to find shit like positions, cost, owner, garage or whatever the hell.
• Add those things to a dini file in "scriptfiles\Houses"

BUT - what should I name the file, and how would I load it OnGameModeInit, if I have, say, 100 houses?

In other words, I need to loop through all house-files and load them. How?

That's my problem, pretty much.

ALSO: I DON'T want your goddamn includes or FilterScripts. I don't learn shit by using someone elses work, I wanna do it myself.
Reply
#2

Why don't add all houses in same file, then loop through the lines and use sscanf to extract the info?
Reply
#3

You can name it whatever you want.

As for reading from the files: use "while(fread())" along with strfind. It goes through all lines in the file, so it should provide everything you need. Hope you could use it, if you need some more info feel free to ask.
Reply
#4

Quote:
Originally Posted by LarzI
Посмотреть сообщение
Why don't add all houses in same file, then loop through the lines and use sscanf to extract the info?
I would build the file like:

HouseName="FuckingAwesomeRoad 1" (or whatever strings looks like. ._.)
HouseX=0.001
HouseY=0.002
HouseZ=0.003
HouseInterior=1
HouseWorld=43
HouseCost=100000
HouseOwner="John_Doe"

or something like that. How'm I supposed to have multiple of those in the same file?

I can do a lot of stuff, but I'm really a noob when it comes to dini. :P

I heard fwrite/fexist/fremove, whatever that include is called, can work too?


@Hiddos: My problem is not READING the files, my problem is LOADING them.
Reply
#5

Quote:
Originally Posted by CrucixTM
Посмотреть сообщение
I would build the file like:

HouseName="FuckingAwesomeRoad 1" (or whatever strings looks like. ._.)
HouseX=0.001
HouseY=0.002
HouseZ=0.003
HouseInterior=1
HouseWorld=43
HouseCost=100000
HouseOwner="John_Doe"

or something like that. How'm I supposed to have multiple of those in the same file?

I can do a lot of stuff, but I'm really a noob when it comes to dini. :P

I heard fwrite/fexist/fremove, whatever that include is called, can work too?


@Hiddos: My problem is not READING the files, my problem is LOADING them.
What do you mean ? What's the difference in this case; loading and reading a file?
Reply
#6

Quote:
Originally Posted by CrucixTM
Посмотреть сообщение
I would build the file like:

HouseName="FuckingAwesomeRoad 1" (or whatever strings looks like. ._.)
HouseX=0.001
HouseY=0.002
HouseZ=0.003
HouseInterior=1
HouseWorld=43
HouseCost=100000
HouseOwner="John_Doe"

or something like that. How'm I supposed to have multiple of those in the same file?

I can do a lot of stuff, but I'm really a noob when it comes to dini. :P

I heard fwrite/fexist/fremove, whatever that include is called, can work too?


@Hiddos: My problem is not READING the files, my problem is LOADING them.
What I meant was using a delimiter like ' | '

HouseName=FuckingAwesomeRoad|HouseX=0.001|HouseY=0 .0002

etc.

Then use sscanf to read and divide the lines up.
Reply
#7

Quote:
Originally Posted by LarzI
Посмотреть сообщение
What I meant was using a delimiter like ' | '

HouseName=FuckingAwesomeRoad|HouseX=0.001|HouseY=0 .0002

etc.

Then use sscanf to read and divide the lines up.
In this case (for him to see) it would be:
pawn Код:
sscanf(const data[], "p<|>sfffddds", {Float,_}:...);
Reply
#8

Ahб. Smart!

@The Toni:
Loading: Finding the actual dini file in the folder(So the script knows WHERE to read)
Reading: Reading the information inside the file(The script takes in info from the file)

If that helps to understand my point.

The delimiter thing was clever, however, how do I write that?

I mean now, I would do something like dini_IntSet or dini_Set, is there an option simply just to write a line/string(no equations)? Is that 'fwrite'?


EDIT: And, I guess for sscanf to function, the line would be
Код:
Housename|0.001|0.002|0.003|100000| etc.
INSTEAD of:

Код:
Housename=Housename|HouseX=0.001|HouseY=0.002|HouseZ=0.003|Housecost=100000| etc.
Right? Sscanf would fuck up if those equations are there?
Reply
#9

Get the YSF plugin.

Then use this (Assuming your directory is Houses, if not change it):

pawn Код:
new filename[40], filepath[40], i;
while(ffind("Houses/*", filename, 64, i)) {
    format(filepath, sizeof(filepath), "Houses/%s", filename);
}
This will loop through ALL files in that directory, and filepath will include the path to that file.
Reply
#10

Quote:
Originally Posted by Conroy
Посмотреть сообщение
Get the YSF plugin.

Then use this (Assuming your directory is Houses, if not change it):

pawn Код:
new filename[40], filepath[40], i;
while(ffind("Houses/*", filename, 64, i)) {
    format(filepath, sizeof(filepath), "Houses/%s", filename);
}
This will loop through ALL files in that directory, and filepath will include the path to that file.
pawn Код:
new filename[40], filepath[40], i;
while(ffind("Houses/*", filename, 64, i))
{
    format(filepath, sizeof(filepath), "Houses/%s", filename);
    houseid = dini_Get(filepath, "HouseID")
    HouseInfo[houseid][Name] = dini_Get(filepath, "Housename")
    etc.
}
Something like that, then?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)