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

Settings API (load/save data to INI files)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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 - 3136 views - 28.0 KB)
File Type: inc amx_settings_api.inc (1.4 KB, 1944 views)
__________________

Last edited by Arkshine; 08-07-2014 at 16:31.
MeRcyLeZZ is offline
 



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 07:42.


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