View Single Post
Author Message
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 03-20-2023 , 17:04   [CS:GO] CSGOItemsJSON
Reply With Quote #1

hello, just a quick snippet that uses game files to generate csgoitems in a json format

PHP Code:
#pragma newdecls required
public void OnPluginStart() 
{
    
char path[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMpathsizeof(path), "../../scripts/items/items_game.txt");

    
char jsonpath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMjsonpathsizeof(jsonpath), "../../scripts/items/items_game.json");

    
char last[4096], curr[4096];
    
char explodeString[3][4096];
    
int strings;

    
File file OpenFile(path"r");
    
File json OpenFile(jsonpath"w");

    
file.ReadLine(currsizeof(curr));
    
    while (!
file.EndOfFile()) {
        
file.ReadLine(currsizeof(curr));
        
TrimString(curr);

        if (
strcmp(curr"{") == 0) {
            if (
strlen(last) > 0json.WriteLine("%s:"last);
        } else if (
strcmp(curr"}") == 0) {
            if (
strings == 3json.WriteLine("%s: %s"explodeString[0], explodeString[2]);
            else 
json.WriteLine("%s"last);
        } else {
            if (
strings == 3json.WriteLine("%s: %s,"explodeString[0], explodeString[2]);
            else {
                if (
strcmp(last"}") == 0json.WriteLine("},");
                else 
json.WriteLine("%s"last);
            }
        }

        
strings ExplodeString(curr"\t"explodeStringsizeof(explodeString), 4096);
        
strcopy(lastsizeof(last), curr);
    }

    
delete file;
    
delete json;

__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline