AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [CS:GO] CSGOItemsJSON (https://forums.alliedmods.net/showthread.php?t=342240)

OSWO 03-20-2023 17:04

[CS:GO] CSGOItemsJSON
 
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;




All times are GMT -4. The time now is 15:08.

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