Convert dini to y_ini
#1

How to convert this dini varialbes in Y_INI?

OnGameModeInit:

pawn Code:
TotalBans = dini_Int("settings.txt","TotalBans");
OnGameModeExit:

pawn Code:
dini_IntSet("settings.txt","TotalBans",TotalBans);
Thanks guys.
Reply
#2

Bump.
Reply
#3

Yes,and i tried also,i can't get realized.
Reply
#4

Quote:
Originally Posted by Y_Less
View Post
OK, well show us the code you tried. If "settings.ini" is a constant file name, it's much simpler as you can use "INI_Load" instead of "INI_ParseFile".
I tried in this way:
Settings.ini is the server stats file,where all stats are saved (like total kicks,bans,accounts).

pawn Code:
INI_Int("TotalBans",TotalBans);
INI_WriteInt(settings.txt,"TotalBans",TotalBans);
Reply
#5

Quote:
Originally Posted by Y_Less
View Post
Are you SURE you read the tutorial? You can't use "INI_Int" like that outside an INI callback.
I use INI_Int inside OnGameModeInit and INI_WriteInt inside OnGameModeExit.
Reply
#6

Quote:
Originally Posted by Y_Less
View Post
So when I said "have you read the y_ini tutorial" and you said "yes"? Did you actually read any of it?
I'm new to Y_INI,as you can see that dini is from my old gamemode and i wish to convert it.
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
Yes, that's why you need to read the topics on it? Have you honestly read and understood them thoroughly?
I'll try to re-read,thanks.
Reply
#8

What Y_Less is trying to say is your going to have to Parse the file as it uses 2 parameters to load the data, for example here is my account loading.

As you can see here these parameters are 'name[]', 'value[]'

pawn Code:
forward LoadVehicle_Main(vehicleid, name[], value[]);
public LoadVehicle_Main(vehicleid, name[], value[])
Now we need to focus in on the 'LoadVehicle_' for get the tag for now which is 'Main'. This is detected by the Y_INI Parser when you parse the file. Before we go into that let me show you how to load a basic varaible from the file.


INI_Int("Name of variable in the file", variable you want to load it to.); This tells the parser when your in the file find this data example

INI_Int("Colour[0]", VehicleInfo[vehicleid][vColour][0]); This tells the parse find 'Colour[0]' once you find 'Colour[0]' find the value of it and load it to 'VehicleInfo[vehicleid][vColour][0]'. If the file is like

Code:
[Main]
Colour[0] = 125
The number 125 will be loaded to the variable.

Okay now before we go onto saving I'm going to get you to parse your file.

pawn Code:
INI_ParseFile(VehiclePath(i), "LoadVehicle_%s", .bExtra = true, .extra = i);
Okay as you can see I am here using a stock, ignore it I'm just too lazy to write this completely from scratch. The path is simpley.

pawn Code:
format(string, sizeof(string), "Surreal Roleplay/Vehicles/%i.ini, vehicleid);
This tells the compiler where the file is and its exact name to open it.

Now you will notice the 'LoadVehicle_", is there and in quotes but there is a string on the end, this is your tag and the compiler will pick it up quite easily. However it is calling your forward. Now as you can see I have a '.bExtra' This tells the parser I have extra information which you might now have, if you dont have it is false!. However I do so I'm keeping mine to true as I have VehicleID represented by 'i'. Now add the '%s' to the vey end of your saving. so it looks like this. ' "LoadVehicle_%s" '

Okay so lets get further on and get to the saving! - The end is ni.

When saving it your tag isnt automaticly detected as you have to actualy phycally call it BUT inside your call back which I will explain in a second but first we need to load out file!.

YOu can load it like this.

new INI:File = INI_Open(VehiclePath(vehicleid)); - This is self explainitory so I wont explain this however you need to add this to the very top of your saving. Simply INI: tells the new its a INI file from the Y_INI include.

Now you have open'd your file above you would have relised I had in my INI FIle '[Main]' Thats your tag, any data below that tag is from this callback as you have set the tag here. NEVER Set a tag in 2 differnt callbacks to the same THING! Unless the loading is differnt here "LoadVehicle_%s" and that the TAG is differnt or your data wil get corrupt.

So lets now explain your tag.

pawn Code:
INI_SetTag(File, "Main");
'INI_SetTag' means that you want to set the tag of a file.
YOu will now also see '(File,' This was decaled above with 'INI:File = INI_Open'

Now before we go anywhere else you will notice I have "Main" this matches my File output, My callback, AND here. This is because this cannot change this defines what the wrtier writes uner.

Then simply once you have done that it gets into the same as DINI sort of and the same of loading.

INI_WriteInt(File, "Colour[0]", VehicleInfo[vehicleid][vColour][0]); Okay you will notice this is near enough the same as the loading BUT we are now writing so lets break this down.

INI_Write This tells the include we want to write kind sir.

I forgot to explain this earlyer so you might have to change somthing 'Int' defines a Interger you are loding this is differnt with INI_String, INI_WriteString, and INI_FLoat etc.

Now 'File' does the exact same thing as it does on the tage it says we want to write in this File kindsir.
We then go onto "Colour[0]" this tells the writer we want it to be kind enough to write this exact line to our file and put a nice little variable after it.

YOu will then see this VehicleInfo[vehicleid][vColour][0], this is a value you want written in this case lets say I have changed my variable to 63 I want that written, equally you can use GetVehicleColor(); and split it into 2 variables being Colour1, Colour2 thats basic I'm sure you understand that.

After you have finished with all these INI_WriteInt(File, "Colour[0]", VehicleInfo[vehicleid][vColour][0]); we need to Close the file or well I dont know the or but you have to. so after you have finished add this.

pawn Code:
INI_Close(File);
This says we want to close the file, it then says

WHAT FILE! You then say to the Kind sir I have defined it as File.

It then takes all this and says Feel Like a Sir while I hadle your new COMPLETE file system.

If you need anymore help add my Skype as I'm pissed off with typing now .
Reply
#9

IceCube,i never expected someone writing me a tutorial.

You're awesome,i really appreciate it.Thanks a lot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)