Raised This Month: $ Target: $400
 0% 

Module: Parser (JSON Reader) Win32


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-08-2014 , 11:35   Module: Parser (JSON Reader) Win32
Reply With Quote #1

Parser (JSON Reader)



Download
View CPP File

This module will allow you to parse files more easily, like listed below.
This is very recommended when you want to precache files, enumerate swears and set entity variables such viewmodel.
Linux version will be done ASAP.


configuration.ini file.

PHP Code:
{
   
"encoding" "UTF8",
   
"latitude" : -21.512312,
   
"maxplayers" 128,

   
"plugins" : [
      
"This1",
      
"This2"
   
]

parser.sma file.

PHP Code:
#include <amxmodx>
#include <parser>

public plugin_init()
{
    new 
parserFile:fileId;
    new 
gameName[16], configsDir[128], fileName[256];
    new 
encodingString[32], Float:cityLatitudemaxPlayers;

    
get_modname(gameNamecharsmax(gameName));
    
get_localinfo("amxx_configsdir"configsDircharsmax(configsDir));
    
formatex(fileNamecharsmax(fileName), "%s/%s/configuration.ini"gameNameconfigsDir);

    
/** If file does not exist, plugin_init forward will stop here.
      */
    
fileId parserLoadFile(fileName);

    
/** Reads all plugins.
      */
    
parserEnumData(fileId"plugins");

    
parserGetString(fileId"encoding"encodingStringcharsmax(encodingString));
    
cityLatitude parserGetFloat(fileId"latitude");
    
maxPlayers parserGetInt(fileId"maxplayers");

    
server_print("Encoding = %s, Latitude = %f, MaxPlayers = %d"encodingStringcityLatitudemaxPlayers);
}

public 
parserEnumForward(parserFile:fileIndexkeyName[], bufferSet[])
{
    
/** Prints to server all plugins.
      */
    
server_print(bufferSet);

parser.inc file.

PHP Code:
#if !defined PARSER_INC

#define PARSER_INC

#include <amxmodx>

#if AMXX_VERSION_NUM >= 175
 #pragma reqlib parser

 #if !defined AMXMODX_NOAUTOLOAD
  #pragma loadlib parser
 #endif
#else
 #pragma library parser
#endif

/** Example of file to be parsed.
  *
  *   {
  *       "encoding" : "utf-8",
  *       "maxPlayers" : 32,
  *       "latitude" : 51.213341,
  *
  *       "plugins" : [
  *           "admin.amxx",
  *           "admincmd.amxx",
  *           "adminvote.amxx"
  *       ]
  *   }
  */

/** Prints all items from a named category.
  *
  * @param fileIndex        The file that the information is taken from.
  * @param keyName    The key.
  * @param bufferSet    The buffer taken.
  *
  * @return        Does not matter.
  */
forward parserEnumForward(parserFile:fileIndexkeyName[], bufferSet[]);

/** Parses a file.
  *
  * @param fileName    The file. If you need a path, the game name should be added too.
  *
  * @return        Does not matter.
  */
native parserFile:parserLoadFile(const fileName[]);

/** Enumerates all data from a parsed file regarding the key name.
  *
  * @param fileIndex        The file that the information is taken from.
  * @param keyName    The key.
  *
  * @return        Does not matter.
  */
native parserEnumData(const parserFile:fileIndex, const keyName[]);

/** Retrieves a string by key.
  *
  * @param fileIndex        The file that the information is taken from.
  * @param keyName    The key.
  * @param stringBuffer    The buffer to be filled.
  * @param stringSize    The size of buffer
  *
  * @return        Does not matter.
  */
native parserGetString(const parserFile:fileIndex, const keyName[], stringBuffer[], const stringSize);

/** Retrieves a numerical value by key.
  *
  * @param fileIndex        The file that the information is taken from.
  * @param keyName    The key.
  *
  * @return        The numerical value.
  */
native parserGetInt(const parserFile:fileIndex, const keyName[]);

/** Retrieves a float value by key.
  *
  * @param fileIndex        The file that the information is taken from.
  * @param keyName    The key.
  *
  * @return        The float value.
  */
native Float:parserGetFloat(const parserFile:fileIndex, const keyName[]);

#endif 
__________________

Last edited by claudiuhks; 04-08-2014 at 11:49.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
 



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 16:25.


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