Raised This Month: $12 Target: $400
 3% 

Settings API (load/save data to INI files)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 07-01-2014 , 06:47   Settings API (load/save data to INI files)
Reply With Quote #1

Settings API

API to load/save settings in a Key+Value format that resembles Windows INI files (http://en.wikipedia.org/wiki/INI_file).

What's new is you can store a variable amount of values in a single key, supporting the use of amxx dyamic arrays.

Use Case:

You want your plugin to use custom sounds and models, then allow users to change them. Previously it would require coding a section into the .sma file, making recompile necessary every time you want to change something. This API allows resources to be edited "externally" through the INI file instead.

Example:

Load admin knife models from file, store them in dynamic array. If section/key is not found, a new entry will be added automatically.
Code:
#define SETTINGS_FILE "plugin_resources.ini" #define MODEL_MAX_LENGTH 64 new const default_model_vknife[] = { "models/v_knife.mdl" } // Default model new Array:g_array_models_admin_vknife public plugin_precache() {     g_array_models_admin_vknife = ArrayCreate( MODEL_MAX_LENGTH, 1 )         if ( !amx_load_setting_string_arr( SETTINGS_FILE, "Admin Models", "V_KNIFE", g_array_models_admin_vknife ) )     {         amx_save_setting_string( SETTINGS_FILE, "Admin Models", "V_KNIFE", default_model_vknife )         ArrayPushString( g_array_models_admin_vknife, default_model_vknife )     } }
File syntax:
Code:
; Add custom admin models here
[Admin Models]
V_KNIFE = models/admin/v_knife_dragon.mdl , models/admin/v_knife_nyan.mdl , models/admin/v_knife3.mdl
Usage:

Download files below into your scripting folder, then do: #include <amx_settings_api>.
Attached Files
File Type: sma Get Plugin or Get Source (amx_settings_api.sma - 3091 views - 28.0 KB)
File Type: inc amx_settings_api.inc (1.4 KB, 1920 views)
__________________

Last edited by Arkshine; 08-07-2014 at 16:31.
MeRcyLeZZ is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 07-01-2014 , 07:09   Re: Settings API (load/save data to INI files)
Reply With Quote #2

Awesome, finally you released it.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-01-2014 , 14:16   Re: Settings API (load/save data to INI files)
Reply With Quote #3

What's the difference between using "txt" files and "ini" files? Or "cfgs", and others? I don't really know

This would be good as a 3rd party module, for avoiding usage
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-01-2014 , 15:08   Re: Settings API (load/save data to INI files)
Reply With Quote #4

I think I will try to import TextParser from SourceMod. It supports INI and Json format. An unified API would be welcomed.
__________________

Last edited by Arkshine; 07-01-2014 at 15:08.
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-01-2014 , 15:09   Re: Settings API (load/save data to INI files)
Reply With Quote #5

I guess I really don't understand the purpose. It appears to me that it's just a global .ini file that can be used by several plugins at once instead of each plugin using it's own.


Quote:
Originally Posted by meTaLiCroSS View Post
What's the difference between using "txt" files and "ini" files? Or "cfgs", and others? I don't really know
A .ini file is a text file with a specific syntax. Take a look at the Wikipedia document linked to in the original post.
__________________
fysiks is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 07-01-2014 , 15:27   Re: Settings API (load/save data to INI files)
Reply With Quote #6

Quote:
Originally Posted by meTaLiCroSS View Post
What's the difference between using "txt" files and "ini" files? Or "cfgs", and others? I don't really know
As fysiks said, it's just a text format to save Key/Values in groups.

Quote:
[section1]
a=a
b=b

[section2]
a=1234
color=blue
Quote:
Originally Posted by fysiks View Post
I guess I really don't understand the purpose. It appears to me that it's just a global .ini file that can be used by several plugins at once instead of each plugin using it's own.
If you write an application with a lot of settings to be saved somehow, sometimes INI format it's useful. Just that. Not only to share settings between plugins, you can use this in just one plugin, but a big one like ZP.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 07-01-2014 , 16:57   Re: Settings API (load/save data to INI files)
Reply With Quote #7

MeRcyLeZZ, Thanks man it's awesome, but one question ZP4.3fix5a is using this method for saving loading ?

I think i will go back from ZP5.0.8 to 4.3Fix5a but not shure, just asked
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-01-2014 , 16:58   Re: Settings API (load/save data to INI files)
Reply With Quote #8

Quote:
Originally Posted by Arkshine View Post
I think I will try to import TextParser from SourceMod. It supports INI and Json format. An unified API would be welcomed.
Yes please, I totally need JSON for my current project. Or SMJansson
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 07-01-2014 , 19:29   Re: Settings API (load/save data to INI files)
Reply With Quote #9

Quote:
Originally Posted by CryWolf View Post
MeRcyLeZZ, Thanks man it's awesome, but one question ZP4.3fix5a is using this method for saving loading ?

I think i will go back from ZP5.0.8 to 4.3Fix5a but not shure, just asked
ZP 5.0 versions using this method, older versions doesn't
TheDS1337 is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-01-2014 , 23:32   Re: Settings API (load/save data to INI files)
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
I guess I really don't understand the purpose. It appears to me that it's just a global .ini file that can be used by several plugins at once instead of each plugin using it's own.




A .ini file is a text file with a specific syntax. Take a look at the Wikipedia document linked to in the original post.
Yeah, I saw it, but it changes something the "readability" of it? Would be different reading a .txt from a .ini?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode