[INC] SINI v1.4 - Advanced File Reading/Writing - UPDATED!

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1367
Gender:
United States of America

[INC] SINI v1.4 - Advanced File Reading/Writing - UPDATED!

Post by Archive-Poster »

Startukk INI
UPDATED! Version 1.4

.: Description :.
This include allows you to easily and freely read/write from/to INI/txt files.
It is fast and easy to learn and understand.

.: Features :.

Code: Select all

	Features:
	*	SINI_Create(filename[]);		   	- Create a specific file.
	*	SINI_Delete(filename[]);		   	- Deletes a specific file.
	*	SINI_Open(filename[]); 			   	- Opens a specific file. 			<!> MUST BE USED WHEN READING/WRITING FILE!
	*	SINI_Exists(filename[]);		   	- Checks if a specific file exists.
	*	SINI_Save(); 	       			   	- Saves the current opened file.		<!> MUST BE USED WHEN WRITING TO FILE!
	*	SINI_Close();	       			   	- Closes the current opened file. 		<!> MUST BE USED WHEN FILE IS OPENED!
	*	SINI_WriteString(varname[], string[]);	   	- Writes a String to a file.			<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	*	SINI_WriteInt(varname[], number);	   	- Writes a Integer to a file.			<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	*	SINI_ReadString(varname[], data[], len);	- Reads a String from a file.			<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	*	SINI_ReadInt(varname[], integer);		- Reads an Integer from a file.			<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	*	SINI_RemoveVariable(varname[]);		   	- Removes a variable from a file.		<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	*	SINI_CountLines();			   	- Returns the number of lines in file.		<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	*	SINI_VariableExists(varname[]);		   	- Checks if given variable exists in file. 	<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	* 	SINI_WriteFloat(varname[], Float: floatvar);	- Writes a Float to a file.			<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
	* 	SINI_ReadFloat(varname[], Float: floatvar); 	- Reads a Float from a file.			<!> FILE MUST BE OPENED TO USE THIS FUNCTION!
.: Writing Usage :.

Code: Select all

    SINI_Create("addons/amxmodx/data/SINI_Test.ini"); // Creating a .INI file named SINI_Test that will be located at addons/amxmodx/data/.
    SINI_Open("addons/amxmodx/data/SINI_Test.ini"); // Opening the .INI file we created above.
    SINI_WriteString("Variable1", "Hello World"); // Writing the variable "Variable1" with the string value "Hello World" assigned to it, this will end up as 'Variable1=Hello World' in the file.
    SINI_WriteInt("Variable2", 555); // Writing the variable "Variable2" with the integer value "555" assinged to it,  this will end up as 'Variable2=555' in the file.
    SINI_WriteFloat("Variable3", 1337.1337); // Writing the variable "Variable3" with the float value "1337.1337" assinged to it,  this will end up as 'Variable3=1337.1337' in the file.
    SINI_Save(); // Saving the file as we wrote variables to it.
    SINI_Close(); // Closing the file as we are done using it. 
.: Reading Usage :.

Code: Select all

    new variable1[35], variable2, Float: variable3; // Creating variables that will store our file reading.
    SINI_Open("addons/amxmodx/data/SINI_Test.ini"); // Opening the .INI  file SINI_Test which is located at addons/amxmodx/data/.
    SINI_ReadString("Variable1", variable1, 35); // Reading the variable "Variable1" and storing its string value at variable1.
    SINI_ReadInt("Variable2", variable2); // Reading the variable "Variable2" and storing its integer value at variable2.
    SINI_ReadFloat("Variable3", variable3); // Reading the variable "Variable3" and storing its float value at variable3.
    SINI_Close(); // Closing the file as we are done using it. 
.: Other usages :.

Code: Select all

    new lines = 0; // Creating a variable with will store our lines count in the file we'll open.
    SINI_Open("addons/amxmodx/data/SINI_Test.ini"); // Opening a .INI file named SINI_Test which is located at addons/amxmodx/data/.
    SINI_RemoveVariable("Variable3"); // Removing the variable "Variable3" from the file.
    lines = SINI_CountLines(); // Getting the number of lines in the file and storing it in the variable lines.
    SINI_Save(); // Saving the file as we removed a variable from it.
    SINI_Close(); // Closing the file since we're done using it. 
.: Defines :.

Code: Select all

MAX_FILE_NAME_LEGNTH - Defines the max file name length. (DEFAULT: 80)
MAX_VARS_PER_FILE - Defines the max variables in file. (DEFAULT: 40)
MAX_VAR_NAME_LENGTH - Defines the max variable name. (DEFAULT: 60)
.: Other information :.
There is also a small money saving script.
You can learn from it, Its located in the attachments.
Attachments
SINI.inc.zip
(1.71 KiB) Downloaded 7 times
SINI Money Saving Example.sma.zip
(1.09 KiB) Downloaded 7 times

Who is online

Users browsing this forum: No registered users and 1 guest