Advertisement
Alelluja

Untitled

Dec 16th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 16.80 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <fakemeta>
  4. #include <colorchat>
  5. #include <hamsandwich>
  6. #include <json>
  7. #include <csx>
  8. #include <codmod>
  9.  
  10. #define AUTHOR "aSior - amxx.pl/user/60210-asiorr/"
  11.  
  12. //#define DEBUG
  13.  
  14. #pragma semicolon 1
  15.  
  16. #define MAX_CHARS 33
  17. #define MAX_PLAYERS 32
  18. #define MAX_SKINS 32
  19.  
  20.  
  21. #define getUserCoins(%1) (cod_get_user_coins(%1))
  22. #define setUserCoins(%1,%2) (cod_set_user_coins(%1, %2))
  23.  
  24. native cod_get_user_coins(id);
  25. native cod_set_user_coins(id, wartosc);
  26.  
  27. #define ForRange(%1,%2,%3) for(new %1 = %2; %1 <= %3; %1++)
  28. #define ForArray(%1,%2) for(new %1 = 0; %1 < sizeof %2; %1++)
  29. #define ForFile(%1,%2,%3,%4,%5) for(new %1 = 0; read_file(%2, %1, %3, %4, %5); %1++)
  30. #define ForDynamicArray(%1,%2) for(new %1 = 0; %1 < ArraySize(%2); %1++)
  31. #define ForSkins(%1) for(new %1 = 0; %1 <= MAX_SKINS - 1; %1++)
  32.  
  33. #define ForPlayers(%1) for(new %1 = 1; %1 <= MAX_PLAYERS; %1++)
  34.  
  35. #define vipFlag ADMIN_LEVEL_H
  36. #define svipFlag ADMIN_LEVEL_G
  37.  
  38. // Data enum.
  39. enum skindata (+= 1)
  40. {
  41.     skindataModelV,
  42.     skindataModelP,
  43.     skindataName,
  44.     skindataAccess,
  45.     skindataCSW,
  46.     skindataCost
  47. };
  48.  
  49.  
  50. // Overall skins system prefix.
  51. new const logPrefix[] = "[SKINS SYSTEM]";
  52.  
  53.  
  54. // Path to .json file.
  55. new const jsonFilePath[] = "addons/amxmodx/data/skinsData.json";
  56.  
  57.  
  58. // Determines how many skins will be displayed in menu (change that to prevent menu-overflow).
  59. const skinsPerPage = 5;
  60.  
  61.  
  62. // Config file path.
  63. new const configFilePath[] = "addons/amxmodx/configs/skinsConfig.ini";
  64.  
  65. // Forbidden characters in config file.
  66. new const configFileForbiddenChars[][] =
  67. {
  68.     " ",
  69.     ";",
  70.     "/",
  71.     "\"
  72. };
  73.  
  74.  
  75. // Skins menu commands.
  76. new const skinsMenuCommands[][] =
  77. {
  78.     "/skiny",
  79.     "/skins"
  80. };
  81.  
  82.  
  83. new userSkin[MAX_PLAYERS + 1][MAX_SKINS],
  84.     bool:userDataLoaded[MAX_PLAYERS + 1],
  85.  
  86.     Array:skinModel[2][MAX_SKINS],
  87.     Array:skinName[MAX_SKINS],
  88.     Array:skinAccess[MAX_SKINS],
  89.     Array:skinCSW[MAX_SKINS],
  90.     Array:skinCost[MAX_SKINS],
  91.  
  92.     JSON:jsonHandle;
  93.  
  94. new isVip;
  95.  
  96. public plugin_init()
  97. {
  98.     register_plugin("Skiny", "v1.2", AUTHOR);
  99.  
  100.     // Register every command.
  101.     registerCommands(skinsMenuCommands, sizeof skinsMenuCommands, "weaponsMenu");
  102.  
  103.     register_event("HLTV", "newRound", "a", "1=0", "2=0");
  104.  
  105.     // Get json handle.
  106.     jsonHandle = json_parse(jsonFilePath, true, false);
  107.  
  108.     // Handle json object if invalid.
  109.     if(jsonHandle == Invalid_JSON)
  110.     {  
  111.         jsonHandle = json_init_object();
  112.     }
  113.  
  114.     #if defined DEBUG
  115.    
  116.     register_srvcmd("loadData", "srvcmdLoadData");
  117.    
  118.     #endif
  119. }
  120.  
  121. /*
  122.         [ FORWARDS & MENUS ]
  123. */
  124.  
  125. public plugin_precache()
  126. {
  127.     createArrays();
  128.     loadSkins();
  129.     registerForwards();
  130. }
  131.  
  132. public plugin_end()
  133. {
  134.     json_serial_to_file(jsonHandle, jsonFilePath, true);
  135.  
  136.     json_free(jsonHandle);
  137. }
  138.  
  139. public weaponsMenu(index)
  140. {
  141.     new menuIndex = menu_create("Wybierz bron:", "weaponsMenu_handler"),
  142.         item[MAX_CHARS * 2];
  143.  
  144.     // Loop through every weapon id, add name to menu if at least one was found.
  145.     ForSkins(i)
  146.     {
  147.         // Continue if there are none skins for that weapon.
  148.         if(!ArraySize(skinName[i]))
  149.         {
  150.             continue;
  151.         }
  152.  
  153.         // Get weapon name to upper case and without 'weapon_' prefix.
  154.         getWeaponName(i, item, charsmax(item));
  155.  
  156.         // Add data to menu.
  157.         menu_additem(menuIndex, fmt("%s - skinow: %i", item, ArraySize(skinName[i])), fmt("%i", i));
  158.     }
  159.  
  160.     menu_display(index, menuIndex);
  161.  
  162.     return PLUGIN_HANDLED;
  163. }
  164.  
  165. public weaponsMenu_handler(index, menu, item)
  166. {
  167.     if(item == MENU_EXIT)
  168.     {
  169.         menu_destroy(menu);
  170.        
  171.         return PLUGIN_HANDLED;
  172.     }
  173.  
  174.     new readData[4];
  175.  
  176.     // Read menu data.
  177.     menu_item_getinfo(menu, item, _, readData, charsmax(readData));
  178.  
  179.     menu_destroy(menu);
  180.  
  181.     // Let user choose the skin he wants.
  182.     skinsMenu(index, str_to_num(readData));
  183.  
  184.     return PLUGIN_HANDLED;
  185. }
  186.  
  187. public skinsMenu(index, csw)
  188. {
  189.     new item[MAX_CHARS + 8],
  190.         menuIndex,
  191.         hasAccess[2],
  192.  
  193.         skinFlags,
  194.         skinCostData,
  195.  
  196.         costData[25];
  197.  
  198.     isVip = get_user_flags(index) & vipFlag ? 1 : (get_user_flags(index) & svipFlag ? 2 : 0);
  199.  
  200.     // Get skin name if not default.
  201.     if(userSkin[index][csw] != -1)
  202.     {
  203.         ArrayGetString(skinName[csw], userSkin[index][csw], item, charsmax(item));
  204.     }
  205.    
  206.     // Create menu handler.
  207.     menuIndex = menu_create(fmt("Aktualny skin:\w %s\y^nWybierz nowego skina:", userSkin[index][csw] > -1 ? item : "Brak"), "skinsMenu_handler");
  208.  
  209.     // Add formated data as menu item.
  210.     menu_additem(menuIndex, "Domyslny", fmt("1#0#%i", csw));
  211.  
  212.     // Loop through every skin assigned to CSW_ index and add it's data to menu item.
  213.     ForDynamicArray(i, skinName[csw])
  214.     {
  215.         // Get skin access-data.
  216.         skinFlags = ArrayGetCell(skinAccess[csw], i);
  217.         skinCostData = ArrayGetCell(skinCost[csw], i);
  218.  
  219.         if(isVip == 2)
  220.         {
  221.             skinCostData = floatround(float(skinCostData) * 0.55);
  222.         }
  223.         else if(isVip == 1)
  224.         {
  225.             skinCostData = floatround(float(skinCostData) * 0.75);
  226.         }
  227.  
  228.         // Get skin name.
  229.         ArrayGetString(skinName[csw], i, item, charsmax(item));
  230.  
  231.         // User has access to that skin?
  232.         getSkinAccess(hasAccess, index, skinFlags, skinCostData, item);
  233.  
  234.         if(skinCostData)
  235.         {
  236.             formatex(costData, charsmax(costData), " | Koszt: %i EvilCoinsow", skinCostData);
  237.         }
  238.         // Add data to menu.
  239.         menu_additem(menuIndex, fmt("%s%s%s", hasAccess[0] ? "\w" : "\r", item, costData), fmt("%i#%i#%i", hasAccess[0], hasAccess[1], csw));
  240.     }
  241.  
  242.     menu_setprop(menuIndex, MPROP_PERPAGE, skinsPerPage);
  243.  
  244.     menu_display(index, menuIndex);
  245.  
  246.     return PLUGIN_HANDLED;
  247. }
  248.  
  249. public skinsMenu_handler(index, menu, item)
  250. {
  251.     if(item == MENU_EXIT)
  252.     {
  253.         menu_destroy(menu);
  254.        
  255.         return PLUGIN_HANDLED;
  256.     }
  257.  
  258.     new readData[16],
  259.         intData[10][10],
  260.         weaponIndex,
  261.  
  262.         skinDataInt[4];
  263.  
  264.     // Read menu data.
  265.     menu_item_getinfo(menu, item, _, readData, charsmax(readData));
  266.    
  267.     menu_destroy(menu);
  268.  
  269.     // Get no-access data from menu info.
  270.     split(readData, intData[0], charsmax(intData[]), intData[1], charsmax(intData[]), "#");
  271.     split(intData[1], intData[1], charsmax(intData[]), intData[2], charsmax(intData[]), "#");
  272.  
  273.     // Convert string-data to integers.
  274.     ForRange(i, 0, 2)
  275.     {
  276.         skinDataInt[i] = str_to_num(intData[i]);
  277.     }
  278.  
  279.     // Return if user has no access.
  280.     if(!skinDataInt[0])
  281.     {
  282.         ColorChat(index, RED, "%s^x01 Nie masz dostepu do tego skina. %s.", logPrefix, (skinDataInt[1] == 2 ? "Skin jest za drogi" : "Brakuje ci flag"));
  283.    
  284.         return PLUGIN_HANDLED;
  285.     }
  286.  
  287.     new chosenWeaponName[MAX_CHARS];
  288.  
  289.     // Get CSW_ index.
  290.     weaponIndex = skinDataInt[2];
  291.  
  292.     // Get chosen weapon name.
  293.     getWeaponName(weaponIndex, chosenWeaponName, charsmax(chosenWeaponName));
  294.  
  295.     // Set user skin to chosen one.
  296.     userSkin[index][weaponIndex] = !item ? -1 : item - 1;
  297.  
  298.     // Notify about skin being set to chosen one.
  299.     if(!item)
  300.     {
  301.         ColorChat(index, RED, "%s^x01 Ustawiles domyslnego skina dla ^"^x03%s^x01^".", logPrefix, chosenWeaponName);
  302.     }
  303.     else
  304.     {
  305.         new chosenSkinName[MAX_CHARS];
  306.  
  307.         ArrayGetString(skinName[weaponIndex], userSkin[index][weaponIndex], chosenSkinName, charsmax(chosenSkinName));
  308.  
  309.         if(skinDataInt[0] == 1)
  310.         {
  311.             isVip = get_user_flags(index) & vipFlag ? 1 : (get_user_flags(index) & svipFlag ? 2 : 0);
  312.  
  313.             new cost = ArrayGetCell(skinCost[weaponIndex], userSkin[index][weaponIndex]);
  314.  
  315.             if(isVip == 2)
  316.             {
  317.                 cost = floatround(float(cost) * 0.55);
  318.             }
  319.             else if(isVip == 1)
  320.             {
  321.                 cost = floatround(float(cost) * 0.75);
  322.             }
  323.  
  324.             setUserCoins(index, getUserCoins(index) - cost);
  325.  
  326.             ColorChat(index, RED, "%s^x01 Kupiles skina ^"^x03%s^x01^" dla broni ^"^x03%s^x01^" za^x03 %i^x01.", logPrefix, chosenSkinName, chosenWeaponName, cost);
  327.  
  328.             saveUserSkins(index);
  329.         }
  330.         else
  331.         {
  332.             ColorChat(index, RED, "%s^x01 Ustawiles skina ^"^x03%s^x01^" dla broni ^"^x03%s^x01^".", logPrefix, chosenSkinName, chosenWeaponName);
  333.         }
  334.     }
  335.  
  336.     // Set new model if his current weapon is the one he just changed skin on.
  337.     if(get_user_weapon(index) == weaponIndex)
  338.     {
  339.         setViewmodel(index, weaponIndex);
  340.     }
  341.  
  342.     return PLUGIN_HANDLED;
  343. }
  344.  
  345. public weaponDeploy(entity)
  346. {
  347.     new index = pev(entity, pev_owner),
  348.         weapon = cs_get_weapon_id(entity);
  349.  
  350.     // Return if player isnt alive or his skin is default.
  351.     if(!is_user_alive(index) || userSkin[index][weapon] == -1)
  352.     {
  353.         return;
  354.     }
  355.  
  356.     setViewmodel(index, weapon);
  357. }
  358.  
  359. // Get skins data.
  360. public client_putinserver(index)
  361. {
  362.     setNoSkins(index);
  363.  
  364.     loadUserSkins(index);
  365. }
  366.  
  367. // Save user skins data.
  368. public client_disconnect(index)
  369. {
  370.     saveUserSkins(index);
  371. }
  372.  
  373. public newRound()
  374. {
  375.     ForPlayers(i)
  376.     {
  377.         saveUserSkins(i);
  378.     }
  379. }
  380.  
  381. /*
  382.         [ FUNCTIONS ]
  383. */
  384.  
  385. bool:getSkinAccess(accessArray[], index, flags, cost, name[] = "")
  386. {
  387.     accessArray[0] = 1;
  388.  
  389.     if(hasSkin(index, name))
  390.     {
  391.         accessArray[0] = 2;
  392.  
  393.         return true;
  394.     }
  395.  
  396.     if(cost && getUserCoins(index) < cost)
  397.     {
  398.         accessArray[0] = 0;
  399.         accessArray[1] = 2;
  400.  
  401.         return false;
  402.     }
  403.  
  404.     if(flags && !(get_user_flags(index) & flags))
  405.     {
  406.         accessArray[0] = 0;
  407.         accessArray[1] = 3;
  408.  
  409.         return false;
  410.     }
  411.  
  412.     return true;
  413. }
  414.  
  415. setViewmodel(index, weapon)
  416. {
  417.     if(userSkin[index][weapon] == -1)
  418.     {
  419.         return;
  420.     }
  421.  
  422.     new weaponModel[2][MAX_CHARS];
  423.  
  424.     // Get model paths.
  425.     ForRange(i, 0, 1)
  426.     {
  427.         if(ArraySize(skinModel[i][weapon]))
  428.         {
  429.             ArrayGetString(skinModel[i][weapon], userSkin[index][weapon], weaponModel[i], charsmax(weaponModel[]));
  430.         }
  431.  
  432.         if(!strlen(weaponModel[i]))
  433.         {
  434.             continue;
  435.         }
  436.  
  437.         // Set model on user screen if model is present.
  438.         set_pev(index, i ? pev_weaponmodel2 : pev_viewmodel2, weaponModel[i]);
  439.     }
  440. }
  441.  
  442. // Set every skin to -1 (default).
  443. setNoSkins(index)
  444. {
  445.     ForRange(i, 0, MAX_SKINS - 1)
  446.     {
  447.         userSkin[index][i] = -1;
  448.     }
  449. }
  450.  
  451. registerForwards()
  452. {
  453.     new entityName[MAX_CHARS];
  454.  
  455.     // Loop through every skin and register weaponDeploy event to it's weapon classname.
  456.     ForRange(i, 0, MAX_SKINS - 1)
  457.     {
  458.         if(!ArraySize(skinName[i]))
  459.         {
  460.             continue;
  461.         }
  462.  
  463.         get_weaponname(i, entityName, charsmax(entityName));
  464.  
  465.         if(entityName[0])
  466.         {
  467.             RegisterHam(Ham_Item_Deploy, entityName, "weaponDeploy", true);
  468.         }
  469.     }
  470. }
  471.  
  472. getWeaponName(csw, string[], length)
  473. {
  474.     // Get 'weapon_' name.
  475.     get_weaponname(csw, string, length);
  476.    
  477.     // Clamp down name to get rid of the 'weapon_' prefix.
  478.     format(string, length, string[7]);
  479.  
  480.     // Get name to upper case.
  481.     strtoupper(string);
  482. }
  483.  
  484. loadSkins()
  485. {
  486.     new lineData[MAX_CHARS * 8],
  487.         lineLength,
  488.         bool:lineContinue,
  489.         lineDataArguments[9][MAX_CHARS * 3],
  490.  
  491.         skinCswIndex,
  492.         skinFlagsData,
  493.         skinCostData,
  494.  
  495.         filePath[128];
  496.  
  497.     ForFile(i, configFilePath, lineData, charsmax(lineData), lineLength)
  498.     {
  499.         // Continue if nothing was found on line.
  500.         if(!lineData[0])
  501.         {
  502.             continue;
  503.         }
  504.  
  505.         lineContinue = false;
  506.  
  507.         // Loop through forbidden characters to prevent headache.
  508.         ForArray(i, configFileForbiddenChars)
  509.         {
  510.             if(lineData[0] == configFileForbiddenChars[i][0])
  511.             {
  512.                 lineContinue = true;
  513.  
  514.                 break;
  515.             }
  516.         }
  517.  
  518.         // Continue main loop if found at least one forbidden character on current line.
  519.         if(lineContinue)
  520.         {
  521.             continue;
  522.         }
  523.  
  524.         // Parse line data to strings.
  525.         parse(lineData,
  526.             lineDataArguments[skindataModelV], charsmax(lineDataArguments[]),
  527.             lineDataArguments[skindataModelP], charsmax(lineDataArguments[]),
  528.             lineDataArguments[skindataName], charsmax(lineDataArguments[]),
  529.             lineDataArguments[skindataAccess], charsmax(lineDataArguments[]),
  530.             lineDataArguments[skindataCSW], charsmax(lineDataArguments[]),
  531.             lineDataArguments[skindataCost], charsmax(lineDataArguments[]));
  532.    
  533.         // Get CSW_ index.
  534.         skinCswIndex = str_to_num(lineDataArguments[skindataCSW]);
  535.  
  536.         // Get both P_ and V_ model for weapon. Break loop and continue main loop if file was not present.
  537.         ForRange(i, 0, 1)
  538.         {
  539.             // Continue if model's name length is 0.
  540.             if(!lineDataArguments[skindata:i][0])
  541.             {
  542.                 continue;
  543.             }
  544.  
  545.             // Handle "/models" and ".mdl" formatting.
  546.             format(filePath, charsmax(filePath), "%s%s%s", containi(lineDataArguments[skindata:i], "models/") == -1 ? "models/" : "", lineDataArguments[skindata:i], containi(lineDataArguments[skindata:i], ".mdl") == -1 ? ".mdl" : "");
  547.  
  548.             if(!file_exists(filePath))
  549.             {
  550.                 log_amx("%s ERROR: weapon model %s not found on path (^"%s^").", logPrefix, i ? "P" : "V", filePath);
  551.  
  552.                 lineContinue = true;
  553.             }
  554.  
  555.             // Break out of loop if model file was not found.
  556.             if(lineContinue)
  557.             {
  558.                 continue;
  559.             }
  560.  
  561.             // Add that model to dynamic array.
  562.             ArrayPushString(skinModel[i][skinCswIndex], filePath);
  563.  
  564.             precache_model(filePath);
  565.  
  566.             #if defined DEBUG
  567.  
  568.             log_amx("Precaching file: ^"%s^"", filePath);
  569.  
  570.             #endif
  571.         }
  572.  
  573.         // Continue main loop if at least one model was not found.
  574.         if(lineContinue)
  575.         {
  576.             continue;
  577.         }
  578.        
  579.         // Get skin-access data.
  580.         skinFlagsData = (lineDataArguments[skindataAccess][0] == '0' || !lineDataArguments[skindataAccess]) ? 0 : read_flags(lineDataArguments[skindataAccess]);
  581.         skinCostData = str_to_num(lineDataArguments[skindataCost]);
  582.  
  583.         // Get skin name, access and weapon index.
  584.         ArrayPushString(skinName[skinCswIndex], lineDataArguments[skindataName]);
  585.         ArrayPushCell(skinAccess[skinCswIndex], skinFlagsData);
  586.         ArrayPushCell(skinCSW[skinCswIndex], skinCswIndex);
  587.         ArrayPushCell(skinCost[skinCswIndex], skinCostData);
  588.  
  589.         #if defined DEBUG
  590.        
  591.         // Log currently processed skin data.
  592.         log_amx("%s Added: ^"%s^". Data: (V: ^"%s^") (P: ^"%s^") (Access: (Flags: ^"%s^" (%i)) (CSW: %i) (Cost: %i).",
  593.                 logPrefix,
  594.                 lineDataArguments[skindataName],
  595.                 lineDataArguments[skindataModelV],
  596.                 lineDataArguments[skindataModelP],
  597.                 lineDataArguments[skindataAccess],
  598.                 skinFlagsData,
  599.                 skinCswIndex,
  600.                 skinCostData);
  601.        
  602.         #endif
  603.     }
  604. }
  605.  
  606. createArrays()
  607. {
  608.     // Loop through every weapon id and create dynamic arrays. Since this is created before config file is loaded, we can do nothing to prevent data lose by creating arrays which will never be used.
  609.     ForSkins(i)
  610.     {
  611.         ForRange(j, 0, 1)
  612.         {
  613.             skinModel[j][i] = ArrayCreate(MAX_CHARS, 1);
  614.         }
  615.  
  616.         skinName[i] = ArrayCreate(MAX_CHARS, 1);
  617.         skinAccess[i] = ArrayCreate(1, 1);
  618.         skinCSW[i] = ArrayCreate(1, 1);
  619.         skinCost[i] = ArrayCreate(1, 1);
  620.     }
  621. }
  622.  
  623. saveUserDataInt(index, label[], data, bool:dotNotation = true)
  624. {
  625.     if(!is_user_connected(index) || !userDataLoaded[index])
  626.     {
  627.         return -1;
  628.     }
  629.  
  630.     return json_object_set_number(jsonHandle, fmt("%n.%s", index, label), data, dotNotation);
  631. }
  632.  
  633. getUserDataInt(index, label[], bool:dotNotation = true)
  634. {
  635.     if(!is_user_connected(index) && !is_user_connecting(index))
  636.     {
  637.         return -1;
  638.     }
  639.  
  640.     userDataLoaded[index] = true;
  641.  
  642.     return json_object_get_number(jsonHandle, fmt("%n.%s", index, label), dotNotation);
  643. }
  644.  
  645. // BUG: this plugin only saves current weapon, not list of skins, so problem of saving list of skins instead of just the current one remains unsolved.
  646. bool:hasSkin(index, name[])
  647. {
  648.     return bool:(json_object_has_value(jsonHandle, fmt("%n.%s", index, name), _, true) ? (getUserDataInt(index, name, true) > -1 ? true : false) : false);
  649. }
  650.  
  651. stock registerCommands(const array[][], arraySize, function[])
  652. {
  653.     #if !defined ForRange
  654.  
  655.         #define ForRange(%1,%2,%3) for(new %1 = %2; %1 <= %3; %1++)
  656.  
  657.     #endif
  658.  
  659.     #if AMXX_VERSION_NUM < 183
  660.    
  661.     ForRange(i, 0, arraySize - 1)
  662.     {
  663.         ForRange(j, 0, 1)
  664.         {
  665.             register_clcmd(fmt("%s %s", !j ? "say" : "say_team", array[i]), function);
  666.         }
  667.     }
  668.  
  669.     #else
  670.  
  671.     new newCommand[MAX_CHARS];
  672.  
  673.     ForRange(i, 0, arraySize - 1)
  674.     {
  675.         ForRange(j, 0, 1)
  676.         {
  677.             formatex(newCommand, charsmax(newCommand), "%s %s", !j ? "say" : "say_team", array[i]);
  678.             register_clcmd(newCommand, function);
  679.         }
  680.     }
  681.  
  682.     #endif
  683. }
  684.  
  685. /*
  686.         [ DATABASE ]
  687. */
  688.  
  689. loadUserSkins(index)
  690. {
  691.     if(!is_user_connected(index))
  692.     {
  693.         return;
  694.     }
  695.  
  696.     new weaponName[MAX_CHARS];
  697.  
  698.     ForSkins(i)
  699.     {
  700.         if(!ArraySize(skinName[i]))
  701.         {
  702.             continue;
  703.         }
  704.  
  705.         getWeaponName(i, weaponName, charsmax(weaponName));
  706.  
  707.         if(!json_object_has_value(jsonHandle, fmt("%n.%s", index, weaponName), _, true))
  708.         {
  709.             userSkin[index][i] = -1;
  710.  
  711.             continue;
  712.         }
  713.  
  714.         userSkin[index][i] = getUserDataInt(index, weaponName);
  715.     }
  716. }
  717.  
  718. saveUserSkins(index)
  719. {
  720.     if(!is_user_connected(index))
  721.     {
  722.         return;
  723.     }
  724.  
  725.     new weaponName[MAX_CHARS];
  726.  
  727.     ForSkins(i)
  728.     {
  729.         if(!ArraySize(skinName[i]))
  730.         {
  731.             continue;
  732.         }
  733.  
  734.         getWeaponName(i, weaponName, charsmax(weaponName));
  735.  
  736.         saveUserDataInt(index, weaponName, userSkin[index][i]);
  737.     }
  738. }
  739.  
  740. /*
  741.         [ USELESS STUFF ]
  742. */
  743.  
  744. #if defined DEBUG
  745.  
  746. public srvcmdLoadData()
  747. {
  748.     printArrays();
  749. }
  750.  
  751. public printArrays()
  752. {
  753.     new skinsData[3][MAX_CHARS],
  754.         flags,
  755.         cswIndex;
  756.  
  757.     ForSkins(i)
  758.     {
  759.         if(!ArraySize(skinName[i]))
  760.         {
  761.             continue;
  762.         }
  763.  
  764.         ForDynamicArray(j, skinName[i])
  765.         {
  766.             ArrayGetString(skinModel[0][i], j, skinsData[0], charsmax(skinsData[]));
  767.  
  768.             ArrayGetString(skinName[i], j, skinsData[2], charsmax(skinsData[]));
  769.             flags = ArrayGetCell(skinAccess[i], j);
  770.             cswIndex = ArrayGetCell(skinCSW[i], j);
  771.  
  772.             log_amx("Skin data: (Model V: ^"%s^") (Name: ^"%s^") (Access: ^"%i^") (CSW: %i).", skinsData[0], skinsData[2], flags, cswIndex);
  773.         }
  774.     }
  775. }
  776.  
  777. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement